Дайте цвет фона для листа Excel в ASP.NETC#

Место общения программистов C#
Anonymous
Дайте цвет фона для листа Excel в ASP.NET

Сообщение Anonymous »

Я выполняю экспорт в Excel в ASP.NET без использования каких -либо сторонних элементов управления. Как я могу придать цвет фона в мой экспортированный лист Excel? Скажите из ячейки 0-5 (ячейка A-E в Excel)-красный цвет, 6-12-зеленый и т. Д.public static void DataSetToExcel(System.Data.DataSet dtExport, System.Web.HttpResponse response, string strFileName)
{
//Clean up the response Object
response.Clear();
response.Charset = "";

//Set the respomse MIME type to excel
response.ContentType = "application/vnd.ms-excel";

//Opens the attachment in new window
response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName.ToString() + ".xls;");
response.ContentEncoding = Encoding.Unicode;
response.BinaryWrite(Encoding.Unicode.GetPreamble());

//Create a string writer
System.IO.StringWriter stringWrite = new System.IO.StringWriter();

//Create an htmltextwriter which uses the stringwriter
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);

//Instantiate the datagrid

System.Web.UI.WebControls.GridView dgrExport = new System.Web.UI.WebControls.GridView();

//Set input datagrid to dataset table
dgrExport.DataSource = dtExport.Tables[0];

//bind the data with datagrid
dgrExport.DataBind();

//Make header text bold
dgrExport.HeaderStyle.Font.Bold = true;

//bind the modified datagrid
dgrExport.DataBind();

//Tell the datagrid to render itself to our htmltextwriter
dgrExport.RenderControl(htmlWrite);

//Output the HTML
response.Write(stringWrite.ToString());

response.End();
}


Подробнее здесь: https://stackoverflow.com/questions/717 ... in-asp-net

Вернуться в «C#»