如何将数据从dataset导出到excel的模板中
模板已经有现成的了 怎么通过代码将数据导入呢? 谢谢
------解决方案--------------------if (saveFileDialogExl.ShowDialog().ToString() == "OK ")
{
SpreadsheetClass workmdbClass = new SpreadsheetClass();
SpreadsheetClass workmcdClass = new SpreadsheetClass();
Worksheet workmdbsheet = workmdbClass.ActiveSheet;
Worksheet workmcdsheet = workmcdClass.ActiveSheet;
createXlsformat(workmcdsheet);
int k = 2;
foreach (DataRow row in DebitNodeDataSet.Tables[0].Rows)
{
if (row[0].ToString() != " " && row[0].ToString() == "0 ")
{
writeXlsdata(row, workmcdsheet, k);
}
k = k + 1;
}
try
{
string filename;
if (DebitNodeDataSet.Tables[0].Rows.Count > 0)
{
filename = saveFileDialogExl.FileName;
filename = filename.Substring(0, filename.LastIndexOf( ".xls "));
filename = filename + "_DN.xls ";
workmcdClass.Export(filename, SheetExportActionEnum.ssExportActionNone, SheetExportFormat.ssExportXMLSpreadsheet);
}
}
catch (Exception es)
{
MessageBoxHelper.ShowErrorMsg(es.Message, "Error ");
}
MessageBoxHelper.ShowInfoMsg( "Export Path: " + saveFileDialogExl.FileName, "Export successfully ");
}
}
}
------解决方案--------------------http://blog.csdn.net/chengking/archive/2005/11/29/539514.aspx
http://blog.csdn.net/ChengKing/category/292667.aspx
------解决方案--------------------根据模版的格式一步一步的往里面写就行了吧
还有就是替换,例如可以在在模版里面放一个#CustomerCd#,然后用DataSet中的CustomerCd去替换.
------解决方案--------------------TRAIN LI的代码速度太慢
可以试一下:SQL语句取数到EXCEL http://www.onlinedown.net/soft/44040.htm
------解决方案--------------------用我这个方法,只要把Dataset传进去,你就可以导出Excel了:
public void DBWriteToExcel(DataSet myds)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = Application.ExecutablePath;
saveFileDialog1.Filter = "Microsoft Office Excel 工作薄(*.xls)|*.xls ";
saveFileDialog1.OverwritePrompt = true;
saveFileDialog1.FileName = "客服日报查询结果 ";//dtpBegin.Text + "至 " + dtpEnd.Text + "客服日报查询结果 ";
if ((saveFileDialog1.ShowDialog()) == DialogResult.OK)
{
FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);
StreamWriter writer = new StreamWriter(fs, Encoding.Unicode);