using System.IO;using System.Text;namespace iLIS.Common{ ////// 生成Excel文档内容 /// 存入工作流 /// public class ExcelDocumentx { private readonly StreamWriter _streamWriter; public ExcelDocumentx(Stream stream) { _streamWriter = new StreamWriter(stream, Encoding.UTF8); } ////// 写入Excel文件头 /// public void Begin() { const string excelHeader = @""); _streamWriter.Close(); } }} Hitek HitekSoft(C) Ltd., 12.00 "; _streamWriter.WriteLine(excelHeader); } /// /// 添加工作表 /// /// 表单名称 /// 默认行高 /// 默认列宽 public void BeginSheet(string name, double defaultRowHeight = 0, double defaultColumnWidth = 0) { _streamWriter.WriteLine(""); _streamWriter.Write(" "); } ///0.0001) _streamWriter.Write(string.Format(" ss:DefaultRowHeight='{0}'", defaultRowHeight)); //默认列宽 if (defaultColumnWidth > 0.0001) _streamWriter.Write(string.Format(" ss:ss:DefaultColumnWidth='{0}'", defaultColumnWidth)); _streamWriter.WriteLine(">"); } ///
/// 添加标题行 /// /// 标题行的名称 /// 标题行的列宽 public void AddHeaderRow(string[] colNames, double[] colWidths = null) { //列宽 if (colWidths != null && colWidths.Length > 0) { for (int i = 0; i < colWidths.Length; i++) { if (colWidths[i] > 0.0001) _streamWriter.WriteLine(string.Format("", i + 1, colWidths[i])); } } AddRow(colNames, "sH"); } /// /// 添加一行 /// /// 样式名称 /// public void AddRow(object[] vals, string styleName = null) { if (string.IsNullOrEmpty(styleName)) styleName = "sBD"; _streamWriter.WriteLine(""); foreach (var val in vals) { string strval = val == null ? "" : val.ToString() .Replace("<", "<") .Replace(">", ">"); _streamWriter.WriteLine("
"); } ///{1} | \n", styleName, strval); } _streamWriter.WriteLine("/// 完成表单 /// public void EndSheet() { _streamWriter.WriteLine(""); _streamWriter.WriteLine("/// 写入Excel文件结束 完成导出 /// public void End() { _streamWriter.WriteLine("