using Microsoft.Office.Interop.Owc11;
public void painItem(){
SpreadsheetClass Sheet = new SpreadsheetClass();
Sheet.get_Range(Sheet.Cells[1, 1], Sheet.Cells[2, column.Count + 1]).set_RowHeight(20);//设置第一行的高度
Sheet.Columns.AutoFit();//自动适应列
Sheet.get_Range(Sheet.Cells[1, 1], Sheet.Cells[2, column.Count + 1]).set_VerticalAlignment(XlVAlign.xlVAlignCenter);//上下居中
Sheet.get_Range(Sheet.Cells[1, 1], Sheet.Cells[2, column.Count + 1]).set_HorizontalAlignment(XlHAlign.xlHAlignCenter);//左右居中
Sheet.get_Range(Sheet.Cells[2, 1], Sheet.Cells[dt.Rows.Count + 2, 1]).set_ColumnWidth(5);//单元格的列宽
Sheet.get_Range(Sheet.Cells[1, 1], Sheet.Cells[1, 1]).Font.set_Bold(true);//标题行加粗字体
Sheet.get_Range(Sheet.Cells[1, 1], Sheet.Cells[1, 1]).Font.set_Size(14);//设置字体大小
Sheet.get_Range(Sheet.Cells[2, 1], Sheet.Cells[2, column.Count + 1]).Interior.set_ColorIndex(43);//背景色
Sheet.ActiveCell[1, 1] = "数据一览统计表"; //第一行为报表的标题
Sheet.get_Range(Sheet.Cells[1, 1], Sheet.Cells[1, column.Count + 1]).set_MergeCells(true); //合并单元格
Sheet.get_Range(Sheet.Cells[1, 1], Sheet.Cells[dt.Rows.Count + 2, column.Count + 1]).Borders.set_LineStyle(XlLineStyle.xlContinuous);//画边线
string FileName = strAbsolutePath + "WebGraphReportB01.html";
if (File.Exists(FileName))
{
File.Delete(FileName);
}
//将Sheet导出成html格式的数据,在前台页面显示用
Sheet.Export(FileName, SheetExportActionEnum.ssExportActionNone, SheetExportFormat.ssExportHTML);
}
导出成html格式的时候前台页面的内容:
<object classid="clsid:0002E559-0000-0000-C000-000000000046" width="990" id="Spreadsheet1" height="400" align ="middle">
<param name="DataType" value="HTMLURL"/>
<param name="HTMLURL" value="..//WebGraphReportB01.html"/>
</object>
WebGraphReportB01.html的内容如下:
<html xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 9">
<style type="text/css">
<!--tr
{mso-height-source:auto;}
td
{white-space:nowrap;
font-family:宋体;
mso-number-format:General;
font-size:11pt;
font-weight:auto;
font-style:auto;
text-decoration:auto;
mso-background-source:auto;
mso-pattern:auto;
mso-color-source:auto;
text-align:general;
vertical-align:bottom;
border-top:none;
border-left:none;
border-right:none;
border-bottom:none;
mso-protection:locked;}
.wc03F33D38
{white-space:nowrap;
font-family:宋体;
mso-number-format:General;
font-size:11pt;
font-weight:auto;
font-style:auto;
text-decoration:auto;
mso-background-source:auto;
mso-pattern:auto;
mso-color-source:auto;
text-align:general;
vertical-align:bottom;
border-top:none;
border-left:none;
border-right:none;
border-bottom:none;
mso-protection:locked;}
.wc04AAD3A0
{white-space:nowrap;
font-family:宋体;
mso-number-format:General;
font-size:14pt;
font-weight:bold;
font-style:auto;
text-decoration:auto;
mso-background-source:auto;
mso-pattern:auto;
mso-color-source:auto;
text-align:center;
vertical-align:middle;
border-top:solid .5pt black;
border-left:solid .5pt black;
border-right:solid .5pt black;
border-bottom:solid .5pt black;
mso-protection:locked;}
.wc04AAED24
{white-space:nowrap;
font-family:宋体;
mso-number-format:General;
font-size:11pt;
font-weight:auto;
font-style:auto;
text-decoration:auto;
mso-background-source:auto;
mso-pattern:auto;
mso-color-source:auto;
text-align:center;
vertical-align:bottom;
border-top:solid .5pt black;
border-left:solid .5pt black;
border-right:solid .5pt black;
border-bottom:solid .5pt black;
mso-protection:locked;}
.wc04AA49F8
{white-space:nowrap;
font-family:宋体;
mso-number-format:General;
font-size:11pt;
font-weight:auto;
font-style:auto;
text-decoration:auto;
background:#99CC00;
mso-color-source:auto;
text-align:center;
vertical-align:middle;
border-top:solid .5pt black;
border-left:solid .5pt black;
border-right:solid .5pt black;
border-bottom:solid .5pt black;
mso-protection:locked;}
-->
</style>
</head>
<body>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:OWCVersion>11.0.0.5531 </x:OWCVersion>
<x:Label Style='font-family:宋体;font-size:11pt;border-top:solid .5pt silver;
border-left:solid .5pt silver;border-right:solid .5pt silver;border-bottom:
solid .5pt silver'>
<x:Caption>Microsoft Office Spreadsheet</x:Caption>
</x:Label>
<x:Name>Sheet</x:Name>
<x:WorksheetOptions>
<x:Selected/>
<x:Height>7620</x:Height>
<x:Width>15240</x:Width>
<x:DisableUndo/>
<x:DoNotDisplayTitleBar/>
<x:ViewableRange>$1:$262144</x:ViewableRange>
<x:Selection>A1:BY1</x:Selection>
<x:TopRowVisible>0</x:TopRowVisible>
<x:LeftColumnVisible>0</x:LeftColumnVisible>
<x:ProtectContents>False</x:ProtectContents>
<x:DefaultRowHeight>255</x:DefaultRowHeight>
<x:StandardWidth>2304</x:StandardWidth>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:MaxHeight>80%</x:MaxHeight>
<x:MaxWidth>80%</x:MaxWidth>
</x:ExcelWorkbook>
</xml><![endif]-->
<table class=wc03F33D38 cellpadding=0 cellspacing=0 x:str>
<col width="45" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<col width="77" style='mso-width-source:userset'>
<tr height="27" style='mso-height-source:userset;mso-height-alt:405'>
<td class=wc04AAD3A0 x:str="数据一览统计表" colspan="77" style='border-right:solid .5pt black'>数据一览统计表</td>
</tr>
</table>
</body>
</html>