2015-11-05 46 views
-1

我只能在顶部写入不变数据(例如.company名称)。我想写在底部。在Excel底部导出不变数据

将数据导出到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(); 
+0

后你已经尝试 – MusicLovingIndianGirl

+0

代码也做SO或谷歌为这个简单的搜索。就在2秒钟之前,还有另外一个类似的问题。提示:检查EPPlus库 –

+1

以下是代码。 – Shwetha

回答

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

我已经将数据绑定到datagrid。我想写入不变的数据写在excel的底部。 – Shwetha

+0

很难捍卫者:) –