//需要接入 //EPPlus.dll
//OfficeOpenXml
public static string FindConfigContent = "";
[MenuItem("策划配置/配置内容查找")]
public static void StartFindConfig()
{
var windown = EditorWindow.GetWindow<ConfigFindToolWin>();
windown.titleContent = new GUIContent("设置配置路径");
windown.minSize = new Vector2(1000, 300);
}
public static void FindConfig()
{
allExcelDatas = null;
var dirPath = FindExcelPath(cxcelDirPath);
if (Directory.Exists(dirPath))
{
allXml = GetDirAllXmlPaths(dirPath);
}
if (allXml.Count > 0)
{
for (int i = 0; i < allXml.Count; i++)
{
FileInfo fileInfo = new FileInfo(allXml[i]);
//EPPlus.dll
OfficeOpenXml.ExcelPackage excelPackage = new ExcelPackage(fileInfo);
List<ExcelWorksheet> nwl = null;
if (nwl == null)
{
nwl = new List<ExcelWorksheet>();
var en = excelPackage.Workbook.Worksheets.GetEnumerator();
while (en.MoveNext())
{
var ew = en.Current;
if (!ew.Name.Contains("cfg"))
{
continue;
}
nwl.Add(ew);
}
}
bool isfind = false;
for (int j = 0; j < nwl.Count; j++)
{
var ew = nwl[j];
int minColumnNum = ew.Dimension.Start.Column;//工作区开始列
int maxColumnNum = ew.Dimension.End.Column; //工作区结束列
int minRowNum = ew.Dimension.Start.Row; //工作区开始行号
int maxRowNum = ew.Dimension.End.Row; //工作区结束行号
isfind = false;
for (int rowindex = minRowNum; rowindex <= maxRowNum; rowindex++)
{
for (int colIndex = minColumnNum; colIndex <= maxColumnNum; colIndex++)
{
try
{
if (ew.Cells[rowindex, colIndex].Text.Contains(FindConfigContent))
{
Debug.LogError($"配置表名称 = {ew.Name},第{rowindex}行 ,第{colIndex}列 {ew.Cells[rowindex, colIndex].Text}");
isfind = true; break;
}
}
catch (Exception ex)
{
Debug.LogError(ex.Message);
excelPackage.Dispose();
return;
}
}
if (isfind) break;
}
}
excelPackage.Dispose();
}
}
}
public class ConfigFindToolWin : EditorWindow
{
private string findContent = string.Empty;
private void OnGUI()
{
findContent = EditorGUILayout.TextField("查找的内容:", findContent);
if (GUILayout.Button("开始查找"))
{
BuildConfigTool.FindConfigContent = findContent;
BuildConfigTool.FindConfig();
}
}
}