我想在一个 Excel 文件中创建两个不同的 Excel 工作表。我正在使用 HTML 表格创建 Excel 工作表,并且我想使用 HTML 表格创建第二个 Excel 工作表。下面是我创建和下载 Excel 文件的代码:
StringBuilder _String = new StringBuilder();
_String.Append(" <table border=\"1\" style=\"text-align: center; border-collapse: collapse;font-family: Arial, Helvetica,
sans-serif; font-size: 13px;\" cellpadding=\"5\" cellspacing=\"0\">");
_String.Append("<tr>");
_String.Append("<td style=\"padding: 4px; margin: 3px; height:70px; vertical-align:middle; \" rowspan=\"4\">");
_String.Append(" ");
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px;height:70px; text-align:center; vertical-align:middle; \"
rowspan=\"4\">");
_String.Append(Convert.ToString(_Count));
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px;height:70px; vertical-align:middle; text-align:center; \"
rowspan=\"4\">");
_String.Append(Location);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px;height:70px; vertical-align:middle; text-align:center; \"
rowspan=\"4\">");
_String.Append(ATMCode);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; height:70px; vertical-align:middle;background-color: #c0c0c0;\"
rowspan=\"4\">");
_String.Append(" ");
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; text-align:center; height:70px;
vertical-align:middle;background-color: #c0c0c0;\" rowspan=\"4\">");
_String.Append(Time);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; text-align:center; \">");
_String.Append("1000");
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(OpeningBal_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(OpeningBalAm_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(Dispense_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(DispenseAm_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(Purge_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(PurgeAm_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(Overages_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(OveragesAm_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(shortages_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(shortagesAm_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(ClosingBR_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(ClosingBRAm_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(Rep_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(RepAm_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(CB_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(CBAm_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(TxnNumber);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(" ");
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(Deposit);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(Deposit);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(RetainedCrd);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(" ");
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(SCB_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(SCBAm_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\" rowspan=\"4\">");
_String.Append(" ");
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; background-color: #c0c0c0;\">");
_String.Append(OpeningBal_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px; \">");
_String.Append(OpeningBalAm_1000);
_String.Append("</td>");
_String.Append("<td style=\"padding: 4px; margin: 3px;
height:70px; background-color:#CCFFCC;Color:#2E6C31;
vertical-align:middle; text-align:center;\" rowspan=\"4\">");
_String.Append("<b>" + Status + "</b>");
_String.Append("</td>");
_String.Append("</tr>");
_String.Append("</table>");
下载代码:
Response.ContentType = "application/x-msexcel";
Response.AddHeader("Content-Disposition", "attachment;
filename=ExcelFile.xls"); Response.ContentEncoding = Encoding.UTF8;
Response.Write(_String.ToString()); Response.End();