文档库 最新最全的文档下载
当前位置:文档库 › 用数据流的形式导出Excel

用数据流的形式导出Excel

public void NewShowExcel()
{
string saveFileName = "";
// bool fileSaved=false;
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.DefaultExt = "txt";//xls
saveDialog.Filter = "Excel文件(*.xls)|*.xls";
saveDialog.FileName = "订单回款统计";
if (saveDialog.ShowDialog() == DialogResult.OK)
{//被点了取消
// excelapp.Workbooks.Open (App.path & 工程进度表.xls)

saveFileName = saveDialog.FileName;

object missing = System.Reflection.Missing.Value;

Excel.Application myexcel = new Excel.ApplicationClass();
if (myexcel == null)//检查是否安装Excel
{
MessageBox.Show("无法创建Excel对象,可能您的机子未安装Excel");
return;
}


FileStream fs = new FileStream(saveFileName, FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));

sw.WriteLine("订单编号\t订单来源\t数量\t总金额\t配送费用\t已收金额\t配送方式\t订单提交人\t打印人\t财务\t付款方式\t支付状态\t客户类型\t客户名称\t订单创建日期\t出票日期\t收款日期\t分站名称\t被叫号码");

foreach (UltraGridRow row in this.ugStatistics.Rows)
{
sw.WriteLine(row.Cells["ServerOrderID"].Value + "\t"
+ row.Cells["OrderSourceTmp"].Value + "\t"
+ row.Cells["Quantity"].Value + "\t"
+ row.Cells["Amount"].Value + "\t"
+ row.Cells["DeliveryPrice"].Value + "\t"//5
+ row.Cells["AmountPaid"].Value + "\t"
+ row.Cells["DeliveryMethodTmp"].Value + "\t"
+ row.Cells["CreatUser"].Value + "\t"
+ row.Cells["PrintUser"].Value + "\t"
+ row.Cells["FinancialUser"].Value + "\t" //10
+ row.Cells["PaymethodTmp"].Value + "\t"
+ row.Cells["PayStatusTmp"].Value + "\t"
+ row.Cells["CustomerKindName"].Value + "\t"
+ row.Cells["RealName"].Value + "\t"
+ row.Cells["CreateTime"].Value + "\t" //15
+ row.Cells["PrintDate"].Value + "\t"
+ row.Cells["FinanicalDate"].Value + "\t"
+ row.Cells["DeptName"].Value + "\t"
+ row.Cells["CalledPhoneNum"].Value);
}
sw.Flush();
sw.Close();

FileInfo fifo = new FileInfo(saveFileName);

System.Diagnostics.Process.Start(saveFileName

);

}
else
{
return;
}


}

相关文档
相关文档 最新文档