0
我有下面提到的代碼導出數據到excel使用GridLine導出Excel
Response.Clear(); Response.Buffer = true;
Response.AddHeader("content-disposition",
"attachment;filename=GridViewExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
Table tb = new Table();
GridView gv=new GridView();
tb.GridLines = gv.GridLines;
tb.BackColor = System.Drawing.Color.Transparent;
TableRow tr1 = new TableRow();
TableCell cell1 = new TableCell();
cell1.Controls.Add(BalanceSheetListControl2);
tr1.Cells.Add(cell1);
tb.Rows.Add(tr1);
tb.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { mso-number-format:\@; backgroud-color:transparent !important; } </style>";
Response.Write(style);
System.IO.StringReader writer = new System.IO.StringReader(sw.ToString());
string s=string.Empty;
string readString = string.Empty;
bool StartFlag = false;
StringBuilder build = new StringBuilder();
while((readString=writer.ReadLine())!=null)
{
// readString = writer.ReadLine().Trim();
s = readString;
Regex search_string = new Regex("<div.*?>([^<]+)</div>");
Match match = search_string.Match(s);
string section = match.Groups[1].Value.ToString();
if (section.Trim()=="-")
{
s = s.Replace(">-<", "><div align='right'>-</div><");
// s = s.Replace("-", " - ");
}
if (readString.Trim().Contains("main") || readString.Trim().Contains("column c"))
{
s=s+"</td><td>";
}
build.Append(s);
}
Response.Output.Write(build.ToString());
Response.Flush();
Response.End();
我必須展示在Excel中網格線,我用下面的使用上的代碼後,代碼
GridView gv=new GridView();
tb.GridLines = gv.GridLines;
Excel將只產生垂直網格線,我還需要水平線任何一個可以請幫助我如何實現這一目標? 由於提前
參考我重視我的當前Excel形象
由於它的工作.. :) –
@DhavalPatel不要忘了接受正確的答案,以便它也將成爲別人 –
是的,我已經打上很有幫助。 –