关于导出Execl的问题(怎么样在Excel表头填充中文列名)
Excel.Application excel= new Excel.Application();
int rowIndex=1;
int colIndex=0;
Excel.Workbook workbook=excel.Workbooks.Add(true);
// 怎么样在Excel表头填充中文列名
foreach(DataRow row in table.Rows)
{
rowIndex++;
colIndex=0;
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
}
}
excel.Visible=false;
excel.ActiveWorkbook.SaveAs(strPath,Excel.XlFileFormat.xlExcel9795,null,null,false,false,Excel.XlSaveAsAccessMode.xlNoChange,null,null,null,null,null);
excel.Quit();
excel=null;
GC.Collect();//垃圾回收
------解决方案--------------------up
------解决方案--------------------把excel的第一行设成中文列名不就可以了吗?
------解决方案--------------------Excel.Application excel= new Excel.Application();
int rowIndex=1;
int colIndex=0;
Excel.Workbook workbook=excel.Workbooks.Add(true);
// 怎么样在Excel表头填充中文列名
string[] name ={ "列1 ", "列2 ", "列3 "}//看你有几列了
for(int i=0;i <table.rows.column.count;i++)
{
excel.cells[1][i+1] =name[i]
}
foreach(DataRow row in table.Rows)
{
rowIndex++;
colIndex=0;
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[rowIndex+1,colIndex]=row[col.ColumnName].ToString();
}
}
excel.Visible=false;
excel.ActiveWorkbook.SaveAs(strPath,Excel.XlFileFormat.xlExcel9795,null,null,false,false,Excel.XlSaveAsAccessMode.xlNoChange,null,null,null,null,null);
excel.Quit();
excel=null;
GC.Collect();//垃圾回收
照你的改的,试看看