导出Excel底部的不变数据

本文关键字:数据 Excel 底部 导出 | 更新日期: 2023-09-27 18:20:42

我只能在顶部写入不变数据(例如公司名称)。我想把它写在底部。

将数据导出到Excel时,如何在导出的所有数据的底部写入一组不变数据?

代码(来自评论):

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(); 

导出Excel底部的不变数据

// 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();