我只是WPF的初学者,我在将WPF导出到Excel文件时遇到了一些问题。我的代码顺利进行,但导出的文件有一些奇怪的数字组合,最后一列没有显示数值。请帮我解决这个问题。
此致
private void ExportToExcel()
{
// Open Application
Excel.Application excel = new Excel.Application();
excel.StandardFont = "Times New Roman";
excel.StandardFontSize = 12;
Workbook workbook = excel.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet sheet1 = (Worksheet)excel.Sheets[1];
object misValue = Missing.Value;
excel.Visible = true;
sheet1.Cells[1, 1] = "Temperature";
sheet1.Cells[1, 2] = "Modale";
sheet1.Cells[1, 3] = "Temperature";
sheet1.Cells[1, 4] = "Modale";
sheet1.Cells[1, 5] = "TemperatureMin";
sheet1.Cells[1, 6] = "TemperatureMax";
sheet1.Cells[1, 7] = "ModaleAverage";
for (int i = 0; i < Table1List.Count; i++)
{
Table1 table1 = new Table1();
table1 = Table1List[i];
sheet1.Cells[i + 2, 1] = table1.Temperature.ToString();
sheet1.Cells[i + 2, 2] = table1.Modale.ToString();
}
for (int i = 0; i < Table2List.Count; i++)
{
Table2 table2 = new Table2();
table2 = Table2List[i];
sheet1.Cells[i + 2, 3] = table2.Temperature.ToString();
sheet1.Cells[i + 2, 4] = table2.Modale.ToString();
sheet1.Cells[i + 2, 5] = table2.TemperatureMin.ToString();
sheet1.Cells[i + 2, 6] = table2.TemperatureMax.ToString();
sheet1.Cells[i + 2, 7] = table2.ModaleAverage.ToString();
}
以下是Excel导出文件的照片: