我能够使用Microsoft.Office.Interop.Excel.Worksheet在C#/ VB.net中创建Excel工作表并将其添加到工作簿中,并最终如下所示打开Excel:
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs)
Dim excel As Object = New Microsoft.Office.Interop.Excel.Application()
Dim wb As Object = excel.Workbooks.Add()
Dim wk1 As Object = CType(wb.Sheets.Add(), Microsoft.Office.Interop.Excel.Worksheet)
Dim wk2 As Object = CType(wb.Sheets.Add(), Microsoft.Office.Interop.Excel.Worksheet)
Dim wk3 As Object = CType(wb.Sheets.Add(), Microsoft.Office.Interop.Excel.Worksheet)
wk3.Name = "Work Sheet Three"
wk2.Name = "Work Sheet Two"
wk1.Name = "Work Sheet One"
OpenWorkSheetOne()
OpenWorkSheetTwo()
OpenWorkSheetThree()
excel.Visible = True
wb.Activate()
End Sub
C#
Private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
object excel = new Microsoft.Office.Interop.Excel.Application();
object wb = excel.Workbooks.Add();
object wk1 = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets.Add();
object wk2 = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets.Add();
object wk3 = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets.Add();
wk3.Name = "Work Sheet Three";
wk2.Name = "Work Sheet Two";
wk1.Name = "Work Sheet One";
OpenWorkSheetOne();
OpenWorkSheetTwo();
OpenWorkSheetThree();
excel.Visible = true;
wb.Activate();
}
我有几个工作表,处理时间太长。我想(也许)在不同的线程上同时处理工作表(我想)并将它们同时添加到工作簿中。
我该怎么做并减少处理时间?
我已经用Google搜索,找不到合适的答案。
答案 0 :(得分:0)
尝试使用此库:
https://github.com/ClosedXML/ClosedXML
使用非常简单:
using (var workbook = new XLWorkbook()){
var worksheet = workbook.Worksheets.Add("Sample Sheet");
worksheet.Cell("A1").Value = "Hello World!";
worksheet.Cell("A2").FormulaA1 = "=MID(A1, 7, 5)";
workbook.SaveAs("HelloWorld.xlsx");
}