如何在C#上创建薪水单以精益求精 [英] how to create a salaryslip on c# to excel
本文介绍了如何在C#上创建薪水单以精益求精的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尊敬的先生,
如何在Excel上创建薪水单.我有数据集(ds)中来自数据库的数据.
dear sir,
how to create a salary slip on excel. I have data from database in dataset(ds).
how can design the salary slip based on user-defined format.
推荐答案
http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/ [ ^ ]
现在,您需要知道如何创建XSL.
http://itsrashid.wordpress.com/2007/05/14/export-dataset-to-excel-in-c/[^]
Now you need to know how to create XSL.
创建数据表中的所有薪水单数据,并按excel格式将其导出,如下所示(如果您使用Web应用程序,则使用其他代码进行导出)
Crate all salary slip data in data table and export it in excel format as follow (if you using web application otherwise use another code for export )
public static void exportDataTableToExcel(DataTable table, string name)
{
try
{
HttpContext context = HttpContext.Current;
context.Response.Clear();
context.Response.Buffer = true;
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
context.Response.Write(style);
context.Response.Write("<div> ");
context.Response.Write(Environment.NewLine);
context.Response.Write("<table>");
context.Response.Write(Environment.NewLine);
context.Response.Write("<tr> ");
context.Response.Write(Environment.NewLine);
foreach (DataColumn column in table.Columns)
{
context.Response.Write("<th style = 'font-weight:bold'>");
context.Response.Write(column.ColumnName);
context.Response.Write("</th>");
}
context.Response.Write("</tr>");
foreach (DataRow row in table.Rows)
{
context.Response.Write(Environment.NewLine);
context.Response.Write("<tr> ");
context.Response.Write(Environment.NewLine);
for (int i = 0; i < table.Columns.Count; i++)
{
context.Response.Write("<th style = 'font-weight:Normal' >");
context.Response.Write(row[i].ToString());
context.Response.Write("</th>");
}
context.Response.Write(Environment.NewLine);
context.Response.Write("</tr> ");
context.Response.Write(Environment.NewLine);
}
context.Response.Write("</table>");
context.Response.Write(Environment.NewLine);
context.Response.Write("</div>");
context.Response.Write(Environment.NewLine);
context.Response.AddHeader("content-disposition", "attachment;filename=" + name + ".xls");
context.Response.Charset = "";
context.Response.ContentType = "application/vnd.ms-excel";
context.Response.Flush();
context.Response.End();
}
catch (Exception ex)
{
throw ex;
}
}
这篇关于如何在C#上创建薪水单以精益求精的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文