我有一个 winform 应用程序,我想使用流编写器和 savefiledialog 将我的数据表导出为 office 2007(.xlsx) 格式。但是当我打开 excel 文件时,我遇到了这个错误:文件格式或文件扩展名无效。
Fx_3saveFileDialog.Filter = "Excel 2007-2010 文件 (.xlsx)|*.xlsx; Fx_3saveFileDialog.DefaultExt = "xlsx";
if (Fx_3saveFileDialog.ShowDialog() == DialogResult.OK)
{
dsUrunTableAdapters.PF_FormDegerTableAdapter adapter = new dsUrunTableAdapters.PF_FormDegerTableAdapter();
dsUrun.PF_FormDegerDataTable degertable = new dsUrun.PF_FormDegerDataTable();
adapter.Fill(degertable);
StreamWriter writer = new StreamWriter(Fx_3saveFileDialog.FileName,true);
//StringWriter sw = new StringWriter();
//StringBuilder sb = new StringBuilder(dialog.FileName);
writer.Write("<html>");
writer.Write("<head>");
writer.Write("</head>");
writer.Write("<body>");
writer.Write("<table>");
foreach( DataColumn c in degertable.Columns )
{
//writer.Write(c.Caption);
writer.Write("<td>");
writer.Write(c.Caption);
writer.Write("</td>");
}
writer.Write("</table>");
writer.Write("</body>");
writer.Write("</html>");
//writer.WriteLine();
foreach (DataRow r in degertable.Rows)
{
//writer.Write(r[degertable.SecilebilecekDegerlerColumn].ToString());
}
writer.Close();