c# 导出Excel Xml格式 不用安装Excel也不用引入任何组件
来源:互联网 发布:python msi包下载 编辑:程序博客网 时间:2024/05/21 11:07
public static void CreateExcel(string filepath, int roms, int troms, int zroms, string strdate, Model.Form8 form8)
{
if (filepath != "")
{
StreamWriter rw = new StreamWriter(filepath, false, Encoding.GetEncoding("UTF-8"), 10240);
rw.WriteLine("<?xml version=/"1.0/"?>");
rw.WriteLine("<?mso-application progid=/"Excel.Sheet/"?>");
rw.WriteLine("<Workbook xmlns=/"urn:schemas-microsoft-com:office:spreadsheet/" xmlns:o=/"urn:schemas-microsoft-com:office:office/" xmlns:x=/"urn:schemas-microsoft-com:office:excel/" xmlns:ss=/"urn:schemas-microsoft-com:office:spreadsheet/" xmlns:html=/"http://www.w3.org/TR/REC-html40/">");
rw.WriteLine("<DocumentProperties xmlns=/"urn:schemas-microsoft-com:office:office/">");
rw.WriteLine("<Created>1996-12-17T01:32:42Z</Created>");
rw.WriteLine("<LastSaved>2000-11-18T06:53:49Z</LastSaved>");
rw.WriteLine("<Version>11.8107</Version>");
rw.WriteLine("</DocumentProperties>");
rw.WriteLine("<OfficeDocumentSettings xmlns=/"urn:schemas-microsoft-com:office:office/">");
rw.WriteLine("<RemovePersonalInformation/>");
rw.WriteLine("</OfficeDocumentSettings>");
rw.WriteLine("<ExcelWorkbook xmlns=/"urn:schemas-microsoft-com:office:excel/">");
rw.WriteLine("<WindowHeight>4530</WindowHeight>");
rw.WriteLine("<WindowWidth>8505</WindowWidth>");
rw.WriteLine("<WindowTopX>480</WindowTopX>");
rw.WriteLine("<WindowTopY>120</WindowTopY>");
rw.WriteLine("<AcceptLabelsInFormulas/>");
rw.WriteLine("<ProtectStructure>False</ProtectStructure>");
rw.WriteLine("<ProtectWindows>False</ProtectWindows>");
rw.WriteLine("</ExcelWorkbook>");
rw.WriteLine("<Styles>");
rw.WriteLine("<Style ss:ID=/"Default/" ss:Name=/"Normal/">");
rw.WriteLine("<Alignment ss:Vertical=/"Bottom/"/>");
rw.WriteLine("<Borders/>");
rw.WriteLine("<Font ss:FontName=/"宋体/" x:CharSet=/"134/" ss:Size=/"12/"/>");
rw.WriteLine("<Interior/>");
rw.WriteLine("<NumberFormat/>");
rw.WriteLine("<Protection/>");
rw.WriteLine("</Style>");
rw.WriteLine("<Style ss:ID=/"s24/">");
rw.WriteLine("<Font ss:FontName=/"宋体/" x:CharSet=/"134/" ss:Size=/"9/"/>");
rw.WriteLine("<Alignment ss:Horizontal=/"Center/" ss:Vertical=/"Bottom/"/>");
rw.WriteLine(" <Borders>");
rw.WriteLine(" <Border ss:Position=/"Bottom/" ss:LineStyle=/"Continuous/" ss:Weight=/"1/"/>");
rw.WriteLine("<Border ss:Position=/"Left/" ss:LineStyle=/"Continuous/" ss:Weight=/"1/"/>");
rw.WriteLine("<Border ss:Position=/"Right/" ss:LineStyle=/"Continuous/" ss:Weight=/"1/"/>");
rw.WriteLine("<Border ss:Position=/"Top/" ss:LineStyle=/"Continuous/" ss:Weight=/"1/"/>");
rw.WriteLine("</Borders>");
rw.WriteLine("<NumberFormat ss:Format=/"@/"/>");
rw.WriteLine("</Style>");
rw.WriteLine("<Style ss:ID=/"s25/">");
rw.WriteLine("<Font ss:FontName=/"宋体/" x:CharSet=/"134/" ss:Size=/"9/"/>");
rw.WriteLine("<Alignment ss:Horizontal=/"Center/" ss:Vertical=/"Bottom/"/>");
rw.WriteLine("<Borders>");
rw.WriteLine(" <Border ss:Position=/"Bottom/" ss:LineStyle=/"Continuous/" ss:Weight=/"1/"/>");
rw.WriteLine(" <Border ss:Position=/"Left/" ss:LineStyle=/"Continuous/" ss:Weight=/"1/"/>");
rw.WriteLine(" <Border ss:Position=/"Right/" ss:LineStyle=/"Continuous/" ss:Weight=/"1/"/>");
rw.WriteLine(" <Border ss:Position=/"Top/" ss:LineStyle=/"Continuous/" ss:Weight=/"1/"/>");
rw.WriteLine("</Borders>");
rw.WriteLine("</Style>");
rw.WriteLine("<Style ss:ID=/"s26/">");
rw.WriteLine("<Font ss:FontName=/"宋体/" x:CharSet=/"134/" ss:Size=/"9/"/>");
rw.WriteLine("<Alignment ss:Horizontal=/"Right/" ss:Vertical=/"Bottom/"/>");
rw.WriteLine("</Style>");
rw.WriteLine("<Style ss:ID=/"s27/">");
rw.WriteLine("<Font ss:FontName=/"宋体/" x:CharSet=/"134/" ss:Size=/"9/"/>");
rw.WriteLine("<Alignment ss:Horizontal=/"Left/" ss:Vertical=/"Bottom/"/>");
rw.WriteLine("</Style>");
rw.WriteLine("<Style ss:ID=/"m24861836/">");
rw.WriteLine("<Alignment ss:Horizontal=/"Center/" ss:Vertical=/"Center/"/>");
rw.WriteLine("<Borders/>");
rw.WriteLine("<Font ss:FontName=/"宋体/" x:CharSet=/"134/" ss:Size=/"20/" ss:Bold=/"1/"/>");
rw.WriteLine("<NumberFormat/>");
rw.WriteLine("<Protection ss:Protected=/"0/"/>");
rw.WriteLine("</Style>");
rw.WriteLine("<Style ss:ID=/"s28/">");
rw.WriteLine("<Font ss:FontName=/"宋体/" x:CharSet=/"134/" ss:Size=/"9/"/>");
rw.WriteLine("<Alignment ss:Horizontal=/"Left/" ss:Vertical=/"Bottom/"/>");
rw.WriteLine("<NumberFormat ss:Format=/"@/"/>");
rw.WriteLine("</Style>");
rw.WriteLine("</Styles>");
//sheet
rw.WriteLine("<Worksheet ss:Name=/"Sheet1/">");
rw.WriteLine("<Table x:FullColumns=/"1/" x:FullRows=/"1/" ss:DefaultColumnWidth=/"75/" ss:DefaultRowHeight=/"14.25/">");
if (strdate != null)
{
string[] str = strdate.Split(' ̄');
int cou = 1;
//设置表头
rw.WriteLine("<Row ss:Height=/"31.5/">");
rw.WriteLine("<Cell ss:MergeAcross=/"7/" ss:StyleID=/"m24861836/"><Data ss:Type=/"String/">123123</Data></Cell>");
rw.WriteLine("</Row>");
rw.WriteLine("<Row>");
rw.WriteLine("<Cell ss:StyleID=/"s26/"><Data ss:Type=/"String/">123123</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s27/"/>");
rw.WriteLine("<Cell ss:StyleID=/"s26/"><Data ss:Type=/"String/">123</Data></Cell>");
rw.WriteLine("<Cell ss:MergeAcross=/"2/" ss:StyleID=/"s27/"><Data ss:Type=/"String/">asdasd</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s26/"><Data ss:Type=/"String/">123123</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s28/"><Data ss:Type=/"Number/">123</Data></Cell>");
rw.WriteLine("</Row>");
rw.WriteLine("<Row>");
rw.WriteLine("<Cell ss:MergeAcross=/"1/" ss:StyleID=/"s25/"><Data ss:Type=/"String/">q123</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s25/"><Data ss:Type=/"String/">123</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s25/"><Data ss:Type=/"String/">123</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s25/"><Data ss:Type=/"String/">123</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s25/"><Data ss:Type=/"String/">123</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s25/"><Data ss:Type=/"String/">123</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s25/"><Data ss:Type=/"String/">123</Data></Cell>");
rw.WriteLine("</Row>");
for (int i = 0; i < roms; i++)
{
rw.WriteLine("<Row>");
for (int j = 0; j < 8; j++)
{
if (j == 0)
{
if (i < troms)
{
rw.WriteLine("<Cell ss:StyleID=/"s25/"><Data ss:Type=/"String/">123</Data></Cell>");
}
if (i >= troms && i < (troms + zroms))
{
rw.WriteLine("<Cell ss:StyleID=/"s25/"><Data ss:Type=/"String/">123</Data></Cell>");
}
}
else
{
if (i < (troms + zroms))
{
try
{
if (isNum(str[cou]))
{
rw.WriteLine("<Cell ss:StyleID=/"s24/"><Data ss:Type=/"Number/">" + str[cou] + "</Data></Cell>");
}
else
{
rw.WriteLine("<Cell ss:StyleID=/"s25/"><Data ss:Type=/"String/">" + str[cou] + "</Data></Cell>");
}
cou++;
}
catch (Exception ex) { }
}
}
}
rw.WriteLine("</Row>");
}
}
//设置表尾
rw.WriteLine("<Row>");
rw.WriteLine("<Cell/>");
rw.WriteLine("<Cell ss:StyleID=/"s26/"><Data ss:Type=/"String/">123:</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s27/"><Data ss:Type=/"String/">" + form8.P302 + "</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s26/"><Data ss:Type=/"String/">123:</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s27/"><Data ss:Type=/"String/">" + form8.P303 + "</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s26/"><Data ss:Type=/"String/">123:</Data></Cell>");
rw.WriteLine("<Cell ss:StyleID=/"s27/"><Data ss:Type=/"String/">" + form8.P304 + "</Data></Cell>");
rw.WriteLine("</Row>");
rw.WriteLine("</Table>");
rw.WriteLine("<WorksheetOptions xmlns=/"urn:schemas-microsoft-com:office:excel/">");
rw.WriteLine("<Selected/>");
rw.WriteLine("<ProtectObjects>False</ProtectObjects>");
rw.WriteLine("<ProtectScenarios>False</ProtectScenarios>");
rw.WriteLine("</WorksheetOptions>");
rw.WriteLine("</Worksheet>");
rw.WriteLine("<Worksheet ss:Name=/"Sheet2/">");
rw.WriteLine("<Table ss:ExpandedColumnCount=/"0/" ss:ExpandedRowCount=/"0/" x:FullColumns=/"1/" x:FullRows=/"1/" ss:DefaultColumnWidth=/"54/" ss:DefaultRowHeight=/"14.25/"/>");
rw.WriteLine("<WorksheetOptions xmlns=/"urn:schemas-microsoft-com:office:excel/">");
rw.WriteLine("<Selected/>");
rw.WriteLine("<ProtectObjects>False</ProtectObjects>");
rw.WriteLine("<ProtectScenarios>False</ProtectScenarios>");
rw.WriteLine("</WorksheetOptions>");
rw.WriteLine("</Worksheet>");
rw.WriteLine("<Worksheet ss:Name=/"Sheet3/">");
rw.WriteLine("<Table ss:ExpandedColumnCount=/"0/" ss:ExpandedRowCount=/"0/" x:FullColumns=/"1/" x:FullRows=/"1/" ss:DefaultColumnWidth=/"54/" ss:DefaultRowHeight=/"14.25/"/>");
rw.WriteLine("<WorksheetOptions xmlns=/"urn:schemas-microsoft-com:office:excel/">");
rw.WriteLine("<Selected/>");
rw.WriteLine("<ProtectObjects>False</ProtectObjects>");
rw.WriteLine("<ProtectScenarios>False</ProtectScenarios>");
rw.WriteLine("</WorksheetOptions>");
rw.WriteLine("</Worksheet>");
//sheet
rw.WriteLine("</Workbook>");
rw.Flush();
rw.Close();
}
}
- c# 导出Excel Xml格式 不用安装Excel也不用引入任何组件
- 导出Excel--不用安装office
- 不用插件导出excel
- c#读excel 不用office组件
- asp.net导出数据到Excel的方法(完全无组件,不用调用Excel.exe)
- asp.net导出数据到Excel的方法(完全无组件,不用调用Excel.exe)
- 不用excel组件写数据导入(对excel格式有规定)
- DataSet 导出 Excel 不用COM方式
- php不用第三方类导出excel
- web导出Excel(Xml格式)
- 不用生成临时文件的导出Excel(没有导出模板)
- C# 导出Excel格式设置
- C# 导出Excel 设置格式
- 不用安装Excel使用PSExcel自动处理Excel文件
- C# XML 方式导出Excel
- 最简单的excel导出,啥都不用做
- PHP 中导出EXCEL,最原始方法,不用插件
- 不用gridview将查询结果导出到excel
- 數據庫中索引的簡單原理(引自百度)
- “指针转换”惹得祸
- tips: 黑莓手机语音朗读英文
- Tomcat 6.0 SSL 配置
- spring通过类路径加载xml
- c# 导出Excel Xml格式 不用安装Excel也不用引入任何组件
- ALSA 驱动解决 Ubuntu Linux Intel 集成声卡问题
- Java 生成 keystore || 配置 SSL 的一些指令
- Sharpdevelop学习
- Oracl 用户管理
- 根据年月日,计算出是星期几的牛逼公式
- 在GridView中使用Cache
- 关于分页的讨论 for 小猴
- lotus notes 开发常用方法