excel 导出的 c# 数据未导出
c# data to excel export is not exporting
我目前正在研究一些 C# 并且有一些数据我想导出为 Excel 文件。
我尝试进行第一次测试:
private void myButton11_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application excel;
Microsoft.Office.Interop.Excel.Workbook excelworkbook;
Microsoft.Office.Interop.Excel.Worksheet excelsheet;
excel = new Microsoft.Office.Interop.Excel.Application();
excel.Visible = false;
excel.DisplayAlerts = false;
excelworkbook = excel.Workbooks.Add(Type.Missing);
excelsheet = (Microsoft.Office.Interop.Excel.Worksheet)excelworkbook.ActiveSheet;
excelsheet.Name = "dataToExcel";
excelsheet.Cells[1, 1] = "test";
excelworkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypeXPS,
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard,
true, true, 1, 10, false);
}
它应该创建一个 Excel 文件,其中有一个 sheet,并且在单元格 [1, 1] 中有一个“测试”字符串,
然后导出到我的文档中。
问题是我没有文件,也没有错误,或者导出的消息achieved/failed。代码运行,不崩溃。
知道我的问题出在哪里吗?
谢谢
而不是 Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
也尝试指定一个文件名,
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\mytestfile.xlsx"
我目前正在研究一些 C# 并且有一些数据我想导出为 Excel 文件。
我尝试进行第一次测试:
private void myButton11_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application excel;
Microsoft.Office.Interop.Excel.Workbook excelworkbook;
Microsoft.Office.Interop.Excel.Worksheet excelsheet;
excel = new Microsoft.Office.Interop.Excel.Application();
excel.Visible = false;
excel.DisplayAlerts = false;
excelworkbook = excel.Workbooks.Add(Type.Missing);
excelsheet = (Microsoft.Office.Interop.Excel.Worksheet)excelworkbook.ActiveSheet;
excelsheet.Name = "dataToExcel";
excelsheet.Cells[1, 1] = "test";
excelworkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypeXPS,
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard,
true, true, 1, 10, false);
}
它应该创建一个 Excel 文件,其中有一个 sheet,并且在单元格 [1, 1] 中有一个“测试”字符串, 然后导出到我的文档中。
问题是我没有文件,也没有错误,或者导出的消息achieved/failed。代码运行,不崩溃。
知道我的问题出在哪里吗?
谢谢
而不是 Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
也尝试指定一个文件名,
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\mytestfile.xlsx"