{
try
{
//write
Microsoft.Office.Interop.Excel.Application excelApplication = new Microsoft.Office.Interop.Excel.Application()
Microsoft.Office.Interop.Excel.Workbook workbook = excelApplication.Workbooks.Add(true)
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.ActiveSheet
//excelApplication.Visible = true
#region//填充数据
for (int i = 0 i < dt.Columns.Count - 1 i++)
{
for (int j = 0 j < dt.Rows.Count - 1 j++)
{
excelApplication.Cells[i + 1, j + 1] = dt.Rows[i][j]
//Value.ToString()
}
}
#endregion
//workbook.SaveCopyAs (filepathoutput +"\\"+ strB + ".xlsx")
worksheet.SaveAs(filename + ".xlsx", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)
worksheet = null
workbook.Close(false, Missing.Value, Missing.Value)
excelApplication.Quit()
excelApplication = null
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString())
}
}
如果是我要做这样的事,我就会换一个想法的。行标题不是标题吗?
一个datagridview用一列,这样不就是表标题了吗
你会问,我有好多列啊,那就在这个datagridview中的这个列中插入一个表格啊
这样不就是好多列了吗?
变通…
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)