问题描述,一个datatable 导入到一个excle,但是数据量太大,要创建多个sheet,并继续导数据到新的sheet
代码:if (dt == null) return;
Excel.Application xlApp = new Excel.Application();
if (xlApp == null)
{
lblMsg.Text = "无法创建Excel对象,可能您的机子未安装Excel";
return;
}
Excel.Workbooks workbooks = xlApp.Workbooks;
Excel.Workbook workbook = workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets[1];//取得sheet1
这样创建的excle只有一个sheet页,只能导出6万多数据,怎么添加多个sheet页,并换页操作呢,谢谢你的回答!
------解决方案--------------------------------------------------------
发错区了吧,在汇编里通过COM完成你的功能。
------解决方案--------------------------------------------------------
你的需求描述并不是非常清楚。
如果只是关于创建Worksheet我可以给你两种选择:
使用Microsoft.Office.Interop.Excel以下是一个document-level应用的例子。这个代码为workbook增加了一个名为“Test”的Worksheet
- C# code
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Text;using System.Windows.Forms;using System.Xml.Linq;using Microsoft.Office.Tools.Excel;using Microsoft.VisualStudio.Tools.Applications.Runtime;using Excel = Microsoft.Office.Interop.Excel;using Office = Microsoft.Office.Core;namespace ExcelWorkbook10{ public partial class ThisWorkbook { private void ThisWorkbook_Startup(object sender, System.EventArgs e) { Excel.Workbook objWorkbook = Application.ActiveWorkbook; Excel.Worksheet objWorksheet = objWorkbook.Worksheets.Add(); objWorksheet.Name = "Test"; } private void ThisWorkbook_Shutdown(object sender, System.EventArgs e) { } #region VSTO Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisWorkbook_Startup); this.Shutdown += new System.EventHandler(ThisWorkbook_Shutdown); } #endregion }}