如何使用工作簿打开新的创建Excel文件? [英] How to open new creating excel file using workbook?

查看:134
本文介绍了如何使用工作簿打开新的创建Excel文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





使用以下代码将gridview数据导出为ex​​cel,





export gridview data to excel using the code below,

protected void excelLinkBtn_Click(object sender, EventArgs e)
       {

           Response.Clear();
           Response.AddHeader("content-disposition", "attachment;filename=OverspeedReport.xls");
           Response.Charset = "";
           Response.ContentType = "application/vnd.xls";




           StringWriter stringWrite = new StringWriter();

           HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

           htmlWrite.Write("OVERSPEED REPORT");
           htmlWrite.Write("<br>");

           overspeedReportGrid.AllowPaging = false;
           bindData();



           //'Change the Header Row back to white color
           overspeedReportGrid.HeaderRow.Style.Add("background-color", "#FFFFFF");

           overspeedReportGrid.HeaderStyle.Font.Bold = true;




           //Apply style to Individual Cells
           for (int i = 0; i < overspeedReportGrid.HeaderRow.Cells.Count; i++)
           {
               overspeedReportGrid.HeaderRow.Cells[i].Style.Add("background-color", "#0080C0");

           }

           for (int i = 0; i < loc.Count; i++)
           {
               overspeedReportGrid.Rows[i].Cells[4].Text = loc[i];
           }

           overspeedReportGrid.RenderControl(htmlWrite);
           Response.Write(stringWrite.ToString());
           Response.End();

       }





i希望将excel单元从A3合并到E3以使标题居中''OVERSPEED REPORT''。我找到了一个使用spire.xls dll的代码。



代码如下,





i want to merge the excel cell from A3 to E3 for centering the title ''OVERSPEED REPORT''.I found a code using spire.xls dll.

the code as below,

Workbook workbook = new Workbook();
workbook.LoadFromFile(@"..\mergecells.xls",ExcelVersion.Version97to2003); 
Worksheet sheet = workbook.Worksheets[0];
sheet.Range["A3:E3"].Merge(); 





但如何更改代码行



but how to change line of code

workbook.LoadFromFile(@"..\mergecells.xls",ExcelVersion.Version97to2003); 





在我的代码中添加创建excel OverspeedReport.xls文件?



谢谢...



to add the creating excel OverspeedReport.xls file in my code?

Thanks...

推荐答案

overspeedReportGrid是Excel?如果是,则合并您的数据,而不是将其放在单独的单元格中。对我来说看起来微不足道。
overspeedReportGrid is Excel ? If it is, then merge your data instead of putting it in seperate cells. Looks trivial to me.


这篇关于如何使用工作簿打开新的创建Excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆