简体   繁体   English

在Excel底部导出不变数据

[英]Export invariant data at the bottom of Excel

I am only able to write invariant data (egcompany name) at the top.我只能在顶部写入不变数据(例如公司名称)。 I want to write it at the bottom.我想写在底部。

While exporting data to Excel, how do I write a set of invariant data at the bottom of all data that are being exported?导出数据到Excel时,如何在导出的所有数据的底部写一组不变的数据?

The code (from comment):代码(来自评论):

String strFileName = "ABCReport.xls"; 
Response.ClearContent(); 
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + strFileName + "\""); 
Response.ContentType = "application/excel"; 
System.IO.StringWriter sw = new System.IO.StringWriter(); 
HtmlTextWriter htw = new HtmlTextWriter(sw); 
htw.WriteLine("<b><u><font size='4'>" + "Company name" + " </font></u></b>"); 
htw.WriteLine("<br>"); 
dg.RenderControl(htw); Response.Write(sw.ToString()); 
Response.End(); 
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
    "Extended Properties=Excel 8.0;";

// Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString);

// Open connection with the database.
objConn.Open();

// The code to follow uses a SQL SELECT command to display the data from the worksheet.

// Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM myRange1", objConn);

// Create new OleDbDataAdapter that is used to build a DataSet
// based on the preceding SQL SELECT statement.
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

// Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect;

// Create new DataSet to hold information from the worksheet.
DataSet objDataset1 = new DataSet();

// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, "XLData");

// Bind data to DataGrid control.
DataGrid1.DataSource = objDataset1.Tables[0].DefaultView;
DataGrid1.DataBind();    

// Clean up objects.
objConn.Close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM