/// <summary>
/// 输出到单个Excel文件,考虑超100万的数据 2019.12.24
/// </summary>
/// <param name="config"></param>
/// <param name="xlsxFilename"></param>
/// <param name="dir"></param>
public void Output(ImportConfig config, string xlsxfilename, string dir = "")
{
bool hasTitle = true;
int headLineCount = 0;
int batchCount = 1000000;
uint shtId = 1;
int pageNo = 0, pageCount = 0, total = 0;
Dictionary<string, string> dict = this.GetItems();
if (string.IsNullOrEmpty(dir)) dir = MyCommon.GetDeskTopTimeDir();
xlsxfilename = Path.Combine(dir, xlsxfilename);
using (SpreadsheetDocument doc = SpreadsheetDocument.Create(xlsxfilename, SpreadsheetDocumentType.Workbook))
{
doc.AddWorkbookPart();
List<Sheet> shts = new List<Sheet>();
OpenXmlWriter writer = null;
foreach (var item in dict)
{
using (DbConnection conn = DbFactory.GetConnection(config))
{
conn.Open();
DbCommand cmd = DbFactory.GetCommand(config, item.Value, conn);
DbDataReader reader = cmd.ExecuteReader();
bool pageStart = true;
while (reader.Read())
{
if (pageStart)
{
pageStart = false;
writer = WriteWorksheetPartStart(doc, shts, item.Key, pageNo, shtId);
if (hasTitle)
{
headLineCount = 1;
WriteHeadLine(writer, reader, headLineCount);
}
}
WriteLine(writer, reader, 1 + pageCount + headLineCount);
total++; pageCount++;
if
OpenXML方式输出到Excel(考虑超百万)
最新推荐文章于 2024-06-26 08:00:00 发布