支持同一工作簿内多个sheet导出,跳过#开头的sheet
This commit is contained in:
+583
-493
File diff suppressed because it is too large
Load Diff
@@ -4,34 +4,40 @@ using System.IO;
|
||||
|
||||
namespace ExcelTool.Parser
|
||||
{
|
||||
public class TableExcelExportBytes
|
||||
public static class TableExcelExportBytes
|
||||
{
|
||||
public static bool ExportToFile(string fileName, string outputDir = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(fileName);
|
||||
FileInfo fileInfo = new(fileName);
|
||||
if (string.IsNullOrEmpty(outputDir))
|
||||
{
|
||||
outputDir = fileInfo.DirectoryName;
|
||||
}
|
||||
var excelName = fileInfo.Name.Remove(fileInfo.Name.IndexOf(".xlsx"));
|
||||
//先写入行数,然后每一行的数据一次写入 小写类型、字符串
|
||||
List<Tuple<string, string>> datas = new List<Tuple<string, string>>();
|
||||
var tableData = ExcelHelper.ExcelDatas(fileName);
|
||||
Tuple<string, string> rowCount = new Tuple<string, string>("int", tableData.RowCounts.ToString());
|
||||
datas.Add(rowCount);
|
||||
foreach (var row in tableData.Rows)
|
||||
|
||||
for (int sheetNum = 0; ; sheetNum++)
|
||||
{
|
||||
for (int i = 0; i < tableData.CollonCount; i++)
|
||||
var tableData = ExcelHelper.ExcelDatas(fileName, out string sheetName, out int sheetCount, sheetNum);
|
||||
if (tableData == null || sheetName.StartsWith($"#") || sheetNum > sheetCount)
|
||||
break;
|
||||
|
||||
List<Tuple<string, string>> datas = new();
|
||||
//先写入行数,然后每一行的数据一次写入 小写类型、字符串
|
||||
Tuple<string, string> rowCount = new("int", tableData.RowCounts.ToString());
|
||||
datas.Add(rowCount);
|
||||
foreach (var row in tableData.Rows)
|
||||
{
|
||||
var type = tableData.Headers[i].FieldType.ToLower();
|
||||
var data = row.StrList[i];
|
||||
datas.Add(new Tuple<string, string>(type, data));
|
||||
for (int i = 0; i < tableData.CollonCount; i++)
|
||||
{
|
||||
var type = tableData.Headers[i].FieldType.ToLower();
|
||||
var data = row.StrList[i];
|
||||
datas.Add(new Tuple<string, string>(type, data));
|
||||
}
|
||||
}
|
||||
var binaryFilePath = Path.Combine(outputDir, $"{sheetName}.bytes");
|
||||
FileManager.WriteBinaryDatasToFile(binaryFilePath, datas);
|
||||
}
|
||||
var binaryFilePath = Path.Combine(outputDir, $"{excelName}.bytes");
|
||||
FileManager.WriteBinaryDatasToFile(binaryFilePath, datas);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user