数据导出的结果:

步骤1、新建一个Excel 文档,模板根据自己需要设置

步骤2、使用OpenXml  打开Excel 文件

步骤3、点击ReflectCode 功能,生成相应的代码文档

  1. using DocumentFormat.OpenXml.Packaging;
  2. using Ap = DocumentFormat.OpenXml.ExtendedProperties;
  3. using Vt = DocumentFormat.OpenXml.VariantTypes;
  4. using DocumentFormat.OpenXml;
  5. using DocumentFormat.OpenXml.Spreadsheet;
  6. using X14 = DocumentFormat.OpenXml.Office2010.Excel;
  7. using A = DocumentFormat.OpenXml.Drawing;
  8.  
  9. namespace GeneratedCode
  10. {
  11. public class GeneratedClass
  12. {
  13. // Creates a SpreadsheetDocument.
  14. public void CreatePackage(string filePath)
  15. {
  16. using(SpreadsheetDocument package = SpreadsheetDocument.Create(filePath, SpreadsheetDocumentType.Workbook))
  17. {
  18. CreateParts(package);
  19. }
  20. }
  21.  
  22. // Adds child parts and generates content of the specified part.
  23. private void CreateParts(SpreadsheetDocument document)
  24. {
  25. ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3");
  26. GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1);
  27.  
  28. WorkbookPart workbookPart1 = document.AddWorkbookPart();
  29. GenerateWorkbookPart1Content(workbookPart1);
  30.  
  31. WorksheetPart worksheetPart1 = workbookPart1.AddNewPart<WorksheetPart>("rId3");
  32. GenerateWorksheetPart1Content(worksheetPart1);
  33.  
  34. WorksheetPart worksheetPart2 = workbookPart1.AddNewPart<WorksheetPart>("rId2");
  35. GenerateWorksheetPart2Content(worksheetPart2);
  36.  
  37. WorksheetPart worksheetPart3 = workbookPart1.AddNewPart<WorksheetPart>("rId1");
  38. GenerateWorksheetPart3Content(worksheetPart3);
  39.  
  40. SpreadsheetPrinterSettingsPart spreadsheetPrinterSettingsPart1 = worksheetPart3.AddNewPart<SpreadsheetPrinterSettingsPart>("rId1");
  41. GenerateSpreadsheetPrinterSettingsPart1Content(spreadsheetPrinterSettingsPart1);
  42.  
  43. SharedStringTablePart sharedStringTablePart1 = workbookPart1.AddNewPart<SharedStringTablePart>("rId6");
  44. GenerateSharedStringTablePart1Content(sharedStringTablePart1);
  45.  
  46. WorkbookStylesPart workbookStylesPart1 = workbookPart1.AddNewPart<WorkbookStylesPart>("rId5");
  47. GenerateWorkbookStylesPart1Content(workbookStylesPart1);
  48.  
  49. ThemePart themePart1 = workbookPart1.AddNewPart<ThemePart>("rId4");
  50. GenerateThemePart1Content(themePart1);
  51.  
  52. SetPackageProperties(document);
  53. }
  54.  
  55. // Generates content of extendedFilePropertiesPart1.
  56. private void GenerateExtendedFilePropertiesPart1Content(ExtendedFilePropertiesPart extendedFilePropertiesPart1)
  57. {
  58. Ap.Properties properties1 = new Ap.Properties();
  59. properties1.AddNamespaceDeclaration("vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
  60. Ap.Application application1 = new Ap.Application();
  61. application1.Text = "Microsoft Excel";
  62. Ap.DocumentSecurity documentSecurity1 = new Ap.DocumentSecurity();
  63. documentSecurity1.Text = "0";
  64. Ap.ScaleCrop scaleCrop1 = new Ap.ScaleCrop();
  65. scaleCrop1.Text = "false";
  66.  
  67. Ap.HeadingPairs headingPairs1 = new Ap.HeadingPairs();
  68.  
  69. Vt.VTVector vTVector1 = new Vt.VTVector(){ BaseType = Vt.VectorBaseValues.Variant, Size = (UInt32Value)2U };
  70.  
  71. Vt.Variant variant1 = new Vt.Variant();
  72. Vt.VTLPSTR vTLPSTR1 = new Vt.VTLPSTR();
  73. vTLPSTR1.Text = "工作表";
  74.  
  75. variant1.Append(vTLPSTR1);
  76.  
  77. Vt.Variant variant2 = new Vt.Variant();
  78. Vt.VTInt32 vTInt321 = new Vt.VTInt32();
  79. vTInt321.Text = "3";
  80.  
  81. variant2.Append(vTInt321);
  82.  
  83. vTVector1.Append(variant1);
  84. vTVector1.Append(variant2);
  85.  
  86. headingPairs1.Append(vTVector1);
  87.  
  88. Ap.TitlesOfParts titlesOfParts1 = new Ap.TitlesOfParts();
  89.  
  90. Vt.VTVector vTVector2 = new Vt.VTVector(){ BaseType = Vt.VectorBaseValues.Lpstr, Size = (UInt32Value)3U };
  91. Vt.VTLPSTR vTLPSTR2 = new Vt.VTLPSTR();
  92. vTLPSTR2.Text = "Sheet1";
  93. Vt.VTLPSTR vTLPSTR3 = new Vt.VTLPSTR();
  94. vTLPSTR3.Text = "Sheet2";
  95. Vt.VTLPSTR vTLPSTR4 = new Vt.VTLPSTR();
  96. vTLPSTR4.Text = "Sheet3";
  97.  
  98. vTVector2.Append(vTLPSTR2);
  99. vTVector2.Append(vTLPSTR3);
  100. vTVector2.Append(vTLPSTR4);
  101.  
  102. titlesOfParts1.Append(vTVector2);
  103. Ap.LinksUpToDate linksUpToDate1 = new Ap.LinksUpToDate();
  104. linksUpToDate1.Text = "false";
  105. Ap.SharedDocument sharedDocument1 = new Ap.SharedDocument();
  106. sharedDocument1.Text = "false";
  107. Ap.HyperlinksChanged hyperlinksChanged1 = new Ap.HyperlinksChanged();
  108. hyperlinksChanged1.Text = "false";
  109. Ap.ApplicationVersion applicationVersion1 = new Ap.ApplicationVersion();
  110. applicationVersion1.Text = "14.0300";
  111.  
  112. properties1.Append(application1);
  113. properties1.Append(documentSecurity1);
  114. properties1.Append(scaleCrop1);
  115. properties1.Append(headingPairs1);
  116. properties1.Append(titlesOfParts1);
  117. properties1.Append(linksUpToDate1);
  118. properties1.Append(sharedDocument1);
  119. properties1.Append(hyperlinksChanged1);
  120. properties1.Append(applicationVersion1);
  121.  
  122. extendedFilePropertiesPart1.Properties = properties1;
  123. }
  124.  
  125. // Generates content of workbookPart1.
  126. private void GenerateWorkbookPart1Content(WorkbookPart workbookPart1)
  127. {
  128. Workbook workbook1 = new Workbook();
  129. workbook1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
  130. FileVersion fileVersion1 = new FileVersion(){ ApplicationName = "xl", LastEdited = "5", LowestEdited = "5", BuildVersion = "9302" };
  131. WorkbookProperties workbookProperties1 = new WorkbookProperties(){ DefaultThemeVersion = (UInt32Value)124226U };
  132.  
  133. BookViews bookViews1 = new BookViews();
  134. WorkbookView workbookView1 = new WorkbookView(){ XWindow = 600, YWindow = 75, WindowWidth = (UInt32Value)19395U, WindowHeight = (UInt32Value)7605U };
  135.  
  136. bookViews1.Append(workbookView1);
  137.  
  138. Sheets sheets1 = new Sheets();
  139. Sheet sheet1 = new Sheet(){ Name = "Sheet1", SheetId = (UInt32Value)1U, Id = "rId1" };
  140. Sheet sheet2 = new Sheet(){ Name = "Sheet2", SheetId = (UInt32Value)2U, Id = "rId2" };
  141. Sheet sheet3 = new Sheet(){ Name = "Sheet3", SheetId = (UInt32Value)3U, Id = "rId3" };
  142.  
  143. sheets1.Append(sheet1);
  144. sheets1.Append(sheet2);
  145. sheets1.Append(sheet3);
  146. CalculationProperties calculationProperties1 = new CalculationProperties(){ CalculationId = (UInt32Value)144525U };
  147.  
  148. workbook1.Append(fileVersion1);
  149. workbook1.Append(workbookProperties1);
  150. workbook1.Append(bookViews1);
  151. workbook1.Append(sheets1);
  152. workbook1.Append(calculationProperties1);
  153.  
  154. workbookPart1.Workbook = workbook1;
  155. }
  156.  
  157. // Generates content of worksheetPart1.
  158. private void GenerateWorksheetPart1Content(WorksheetPart worksheetPart1)
  159. {
  160. Worksheet worksheet1 = new Worksheet(){ MCAttributes = new MarkupCompatibilityAttributes(){ Ignorable = "x14ac" } };
  161. worksheet1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
  162. worksheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
  163. worksheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
  164. SheetDimension sheetDimension1 = new SheetDimension(){ Reference = "A1" };
  165.  
  166. SheetViews sheetViews1 = new SheetViews();
  167. SheetView sheetView1 = new SheetView(){ WorkbookViewId = (UInt32Value)0U };
  168.  
  169. sheetViews1.Append(sheetView1);
  170. SheetFormatProperties sheetFormatProperties1 = new SheetFormatProperties(){ DefaultRowHeight = 13.5D, DyDescent = 0.15D };
  171. SheetData sheetData1 = new SheetData();
  172. PhoneticProperties phoneticProperties1 = new PhoneticProperties(){ FontId = (UInt32Value)1U, Type = PhoneticValues.NoConversion };
  173. PageMargins pageMargins1 = new PageMargins(){ Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D };
  174.  
  175. worksheet1.Append(sheetDimension1);
  176. worksheet1.Append(sheetViews1);
  177. worksheet1.Append(sheetFormatProperties1);
  178. worksheet1.Append(sheetData1);
  179. worksheet1.Append(phoneticProperties1);
  180. worksheet1.Append(pageMargins1);
  181.  
  182. worksheetPart1.Worksheet = worksheet1;
  183. }
  1. // Generates content of worksheetPart2.
  2. private void GenerateWorksheetPart2Content(WorksheetPart worksheetPart2)
  3. {
  4. Worksheet worksheet2 = new Worksheet(){ MCAttributes = new MarkupCompatibilityAttributes(){ Ignorable = "x14ac" } };
  5. worksheet2.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
  6. worksheet2.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
  7. worksheet2.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
  8. SheetDimension sheetDimension2 = new SheetDimension(){ Reference = "A1" };
  9.  
  10. SheetViews sheetViews2 = new SheetViews();
  11. SheetView sheetView2 = new SheetView(){ WorkbookViewId = (UInt32Value)0U };
  12.  
  13. sheetViews2.Append(sheetView2);
  14. SheetFormatProperties sheetFormatProperties2 = new SheetFormatProperties(){ DefaultRowHeight = 13.5D, DyDescent = 0.15D };
  15. SheetData sheetData2 = new SheetData();
  16. PhoneticProperties phoneticProperties2 = new PhoneticProperties(){ FontId = (UInt32Value)1U, Type = PhoneticValues.NoConversion };
  17. PageMargins pageMargins2 = new PageMargins(){ Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D };
  18.  
  19. worksheet2.Append(sheetDimension2);
  20. worksheet2.Append(sheetViews2);
  21. worksheet2.Append(sheetFormatProperties2);
  22. worksheet2.Append(sheetData2);
  23. worksheet2.Append(phoneticProperties2);
  24. worksheet2.Append(pageMargins2);
  25.  
  26. worksheetPart2.Worksheet = worksheet2;
  27. }
  28.  
  29. // Generates content of worksheetPart3.
  30. private void GenerateWorksheetPart3Content(WorksheetPart worksheetPart3)
  31. {
  32. Worksheet worksheet3 = new Worksheet(){ MCAttributes = new MarkupCompatibilityAttributes(){ Ignorable = "x14ac" } };
  33. worksheet3.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
  34. worksheet3.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
  35. worksheet3.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
  36. SheetDimension sheetDimension3 = new SheetDimension(){ Reference = "A1:D23" };
  37.  
  38. SheetViews sheetViews3 = new SheetViews();
  39.  
  40. SheetView sheetView3 = new SheetView(){ TabSelected = true, WorkbookViewId = (UInt32Value)0U };
  41. Selection selection1 = new Selection(){ ActiveCell = "D10", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "D10" } };
  42.  
  43. sheetView3.Append(selection1);
  44.  
  45. sheetViews3.Append(sheetView3);
  46. SheetFormatProperties sheetFormatProperties3 = new SheetFormatProperties(){ DefaultRowHeight = 13.5D, DyDescent = 0.15D };
  47.  
  48. Columns columns1 = new Columns();
  49. Column column1 = new Column(){ Min = (UInt32Value)1U, Max = (UInt32Value)1U, Width = 25.25D, CustomWidth = true };
  50. Column column2 = new Column(){ Min = (UInt32Value)2U, Max = (UInt32Value)2U, Width = 35D, CustomWidth = true };
  51. Column column3 = new Column(){ Min = (UInt32Value)3U, Max = (UInt32Value)3U, Width = 20.125D, CustomWidth = true };
  52. Column column4 = new Column(){ Min = (UInt32Value)4U, Max = (UInt32Value)4U, Width = 58.125D, CustomWidth = true };
  53.  
  54. columns1.Append(column1);
  55. columns1.Append(column2);
  56. columns1.Append(column3);
  57. columns1.Append(column4);
  58.  
  59. SheetData sheetData3 = new SheetData();
  60.  
  61. Row row1 = new Row(){ RowIndex = (UInt32Value)1U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 24D, CustomHeight = true, DyDescent = 0.15D };
  62.  
  63. Cell cell1 = new Cell(){ CellReference = "A1", StyleIndex = (UInt32Value)2U, DataType = CellValues.SharedString };
  64. CellValue cellValue1 = new CellValue();
  65. cellValue1.Text = "0";
  66.  
  67. cell1.Append(cellValue1);
  68. Cell cell2 = new Cell(){ CellReference = "B1", StyleIndex = (UInt32Value)2U };
  69. Cell cell3 = new Cell(){ CellReference = "C1", StyleIndex = (UInt32Value)2U };
  70. Cell cell4 = new Cell(){ CellReference = "D1", StyleIndex = (UInt32Value)2U };
  71.  
  72. row1.Append(cell1);
  73. row1.Append(cell2);
  74. row1.Append(cell3);
  75. row1.Append(cell4);
  76.  
  77. Row row2 = new Row(){ RowIndex = (UInt32Value)2U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  78.  
  79. Cell cell5 = new Cell(){ CellReference = "A2", StyleIndex = (UInt32Value)1U, DataType = CellValues.SharedString };
  80. CellValue cellValue2 = new CellValue();
  81. cellValue2.Text = "1";
  82.  
  83. cell5.Append(cellValue2);
  84.  
  85. Cell cell6 = new Cell(){ CellReference = "B2", StyleIndex = (UInt32Value)1U, DataType = CellValues.SharedString };
  86. CellValue cellValue3 = new CellValue();
  87. cellValue3.Text = "2";
  88.  
  89. cell6.Append(cellValue3);
  90.  
  91. Cell cell7 = new Cell(){ CellReference = "C2", StyleIndex = (UInt32Value)1U, DataType = CellValues.SharedString };
  92. CellValue cellValue4 = new CellValue();
  93. cellValue4.Text = "3";
  94.  
  95. cell7.Append(cellValue4);
  96.  
  97. Cell cell8 = new Cell(){ CellReference = "D2", StyleIndex = (UInt32Value)1U, DataType = CellValues.SharedString };
  98. CellValue cellValue5 = new CellValue();
  99. cellValue5.Text = "4";
  100.  
  101. cell8.Append(cellValue5);
  102.  
  103. row2.Append(cell5);
  104. row2.Append(cell6);
  105. row2.Append(cell7);
  106. row2.Append(cell8);
  107. Row row3 = new Row(){ RowIndex = (UInt32Value)3U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  108. Row row4 = new Row(){ RowIndex = (UInt32Value)4U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  109. Row row5 = new Row(){ RowIndex = (UInt32Value)6U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  110. Row row6 = new Row(){ RowIndex = (UInt32Value)8U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  111. Row row7 = new Row(){ RowIndex = (UInt32Value)11U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  112. Row row8 = new Row(){ RowIndex = (UInt32Value)12U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  113. Row row9 = new Row(){ RowIndex = (UInt32Value)13U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  114. Row row10 = new Row(){ RowIndex = (UInt32Value)14U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  115. Row row11 = new Row(){ RowIndex = (UInt32Value)15U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  116. Row row12 = new Row(){ RowIndex = (UInt32Value)16U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 15.75D, DyDescent = 0.15D };
  117. Row row13 = new Row(){ RowIndex = (UInt32Value)18U, Height = 15.75D, DyDescent = 0.15D };
  118. Row row14 = new Row(){ RowIndex = (UInt32Value)19U, Height = 15.75D, DyDescent = 0.15D };
  119. Row row15 = new Row(){ RowIndex = (UInt32Value)20U, Height = 15.75D, DyDescent = 0.15D };
  120. Row row16 = new Row(){ RowIndex = (UInt32Value)21U, Height = 15.75D, DyDescent = 0.15D };
  121. Row row17 = new Row(){ RowIndex = (UInt32Value)22U, Height = 15.75D, DyDescent = 0.15D };
  122. Row row18 = new Row(){ RowIndex = (UInt32Value)23U, Height = 15.75D, DyDescent = 0.15D };
  123.  
  124. sheetData3.Append(row1);
  125. sheetData3.Append(row2);
  126. sheetData3.Append(row3);
  127. sheetData3.Append(row4);
  128. sheetData3.Append(row5);
  129. sheetData3.Append(row6);
  130. sheetData3.Append(row7);
  131. sheetData3.Append(row8);
  132. sheetData3.Append(row9);
  133. sheetData3.Append(row10);
  134. sheetData3.Append(row11);
  135. sheetData3.Append(row12);
  136. sheetData3.Append(row13);
  137. sheetData3.Append(row14);
  138. sheetData3.Append(row15);
  139. sheetData3.Append(row16);
  140. sheetData3.Append(row17);
  141. sheetData3.Append(row18);
  142.  
  143. MergeCells mergeCells1 = new MergeCells(){ Count = (UInt32Value)1U };
  144. MergeCell mergeCell1 = new MergeCell(){ Reference = "A1:D1" };
  145.  
  146. mergeCells1.Append(mergeCell1);
  147. PhoneticProperties phoneticProperties3 = new PhoneticProperties(){ FontId = (UInt32Value)1U, Type = PhoneticValues.NoConversion };
  148. PageMargins pageMargins3 = new PageMargins(){ Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D };
  149. PageSetup pageSetup1 = new PageSetup(){ PaperSize = (UInt32Value)9U, Orientation = OrientationValues.Portrait, Id = "rId1" };
  150.  
  151. worksheet3.Append(sheetDimension3);
  152. worksheet3.Append(sheetViews3);
  153. worksheet3.Append(sheetFormatProperties3);
  154. worksheet3.Append(columns1);
  155. worksheet3.Append(sheetData3);
  156. worksheet3.Append(mergeCells1);
  157. worksheet3.Append(phoneticProperties3);
  158. worksheet3.Append(pageMargins3);
  159. worksheet3.Append(pageSetup1);
  160.  
  161. worksheetPart3.Worksheet = worksheet3;
  162. }
  163.  
  164. // Generates content of spreadsheetPrinterSettingsPart1.
  165. private void GenerateSpreadsheetPrinterSettingsPart1Content(SpreadsheetPrinterSettingsPart spreadsheetPrinterSettingsPart1)
  166. {
  167. System.IO.Stream data = GetBinaryDataStream(spreadsheetPrinterSettingsPart1Data);
  168. spreadsheetPrinterSettingsPart1.FeedData(data);
  169. data.Close();
  170. }
  171.  
  172. // Generates content of sharedStringTablePart1.
  173. private void GenerateSharedStringTablePart1Content(SharedStringTablePart sharedStringTablePart1)
  174. {
  175. SharedStringTable sharedStringTable1 = new SharedStringTable(){ Count = (UInt32Value)5U, UniqueCount = (UInt32Value)5U };
  176.  
  177. SharedStringItem sharedStringItem1 = new SharedStringItem();
  178. Text text1 = new Text();
  179. text1.Text = "用户信息列表";
  180.  
  181. sharedStringItem1.Append(text1);
  182.  
  183. SharedStringItem sharedStringItem2 = new SharedStringItem();
  184. Text text2 = new Text();
  185. text2.Text = "用户编号";
  186.  
  187. sharedStringItem2.Append(text2);
  188.  
  189. SharedStringItem sharedStringItem3 = new SharedStringItem();
  190. Text text3 = new Text();
  191. text3.Text = "公司名称";
  192.  
  193. sharedStringItem3.Append(text3);
  194.  
  195. SharedStringItem sharedStringItem4 = new SharedStringItem();
  196. Text text4 = new Text();
  197. text4.Text = "联系标题";
  198.  
  199. sharedStringItem4.Append(text4);
  200.  
  201. SharedStringItem sharedStringItem5 = new SharedStringItem();
  202. Text text5 = new Text();
  203. text5.Text = "联系人名称";
  204.  
  205. sharedStringItem5.Append(text5);
  206.  
  207. sharedStringTable1.Append(sharedStringItem1);
  208. sharedStringTable1.Append(sharedStringItem2);
  209. sharedStringTable1.Append(sharedStringItem3);
  210. sharedStringTable1.Append(sharedStringItem4);
  211. sharedStringTable1.Append(sharedStringItem5);
  212.  
  213. sharedStringTablePart1.SharedStringTable = sharedStringTable1;
  214. }
  215.  
  216. // Generates content of workbookStylesPart1.
  217. private void GenerateWorkbookStylesPart1Content(WorkbookStylesPart workbookStylesPart1)
  218. {
  219. Stylesheet stylesheet1 = new Stylesheet(){ MCAttributes = new MarkupCompatibilityAttributes(){ Ignorable = "x14ac" } };
  220. stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
  221. stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
  222.  
  223. Fonts fonts1 = new Fonts(){ Count = (UInt32Value)4U, KnownFonts = true };
  224.  
  225. Font font1 = new Font();
  226. FontSize fontSize1 = new FontSize(){ Val = 11D };
  227. Color color1 = new Color(){ Theme = (UInt32Value)1U };
  228. FontName fontName1 = new FontName(){ Val = "宋体" };
  229. FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering(){ Val = 2 };
  230. FontCharSet fontCharSet1 = new FontCharSet(){ Val = 134 };
  231. FontScheme fontScheme1 = new FontScheme(){ Val = FontSchemeValues.Minor };
  232.  
  233. font1.Append(fontSize1);
  234. font1.Append(color1);
  235. font1.Append(fontName1);
  236. font1.Append(fontFamilyNumbering1);
  237. font1.Append(fontCharSet1);
  238. font1.Append(fontScheme1);
  239.  
  240. Font font2 = new Font();
  241. FontSize fontSize2 = new FontSize(){ Val = 9D };
  242. FontName fontName2 = new FontName(){ Val = "宋体" };
  243. FontFamilyNumbering fontFamilyNumbering2 = new FontFamilyNumbering(){ Val = 2 };
  244. FontCharSet fontCharSet2 = new FontCharSet(){ Val = 134 };
  245. FontScheme fontScheme2 = new FontScheme(){ Val = FontSchemeValues.Minor };
  246.  
  247. font2.Append(fontSize2);
  248. font2.Append(fontName2);
  249. font2.Append(fontFamilyNumbering2);
  250. font2.Append(fontCharSet2);
  251. font2.Append(fontScheme2);
  252.  
  253. Font font3 = new Font();
  254. Bold bold1 = new Bold();
  255. FontSize fontSize3 = new FontSize(){ Val = 16D };
  256. Color color2 = new Color(){ Theme = (UInt32Value)1U };
  257. FontName fontName3 = new FontName(){ Val = "宋体" };
  258. FontFamilyNumbering fontFamilyNumbering3 = new FontFamilyNumbering(){ Val = 3 };
  259. FontCharSet fontCharSet3 = new FontCharSet(){ Val = 134 };
  260. FontScheme fontScheme3 = new FontScheme(){ Val = FontSchemeValues.Minor };
  261.  
  262. font3.Append(bold1);
  263. font3.Append(fontSize3);
  264. font3.Append(color2);
  265. font3.Append(fontName3);
  266. font3.Append(fontFamilyNumbering3);
  267. font3.Append(fontCharSet3);
  268. font3.Append(fontScheme3);
  269.  
  270. Font font4 = new Font();
  271. FontSize fontSize4 = new FontSize(){ Val = 11D };
  272. Color color3 = new Color(){ Theme = (UInt32Value)1U };
  273. FontName fontName4 = new FontName(){ Val = "华文中宋" };
  274. FontFamilyNumbering fontFamilyNumbering4 = new FontFamilyNumbering(){ Val = 3 };
  275. FontCharSet fontCharSet4 = new FontCharSet(){ Val = 134 };
  276.  
  277. font4.Append(fontSize4);
  278. font4.Append(color3);
  279. font4.Append(fontName4);
  280. font4.Append(fontFamilyNumbering4);
  281. font4.Append(fontCharSet4);
  282.  
  283. fonts1.Append(font1);
  284. fonts1.Append(font2);
  285. fonts1.Append(font3);
  286. fonts1.Append(font4);
  287.  
  288. Fills fills1 = new Fills(){ Count = (UInt32Value)2U };
  289.  
  290. Fill fill1 = new Fill();
  291. PatternFill patternFill1 = new PatternFill(){ PatternType = PatternValues.None };
  292.  
  293. fill1.Append(patternFill1);
  294.  
  295. Fill fill2 = new Fill();
  296. PatternFill patternFill2 = new PatternFill(){ PatternType = PatternValues.Gray125 };
  297.  
  298. fill2.Append(patternFill2);
  299.  
  300. fills1.Append(fill1);
  301. fills1.Append(fill2);
  302.  
  303. Borders borders1 = new Borders(){ Count = (UInt32Value)1U };
  304.  
  305. Border border1 = new Border();
  306. LeftBorder leftBorder1 = new LeftBorder();
  307. RightBorder rightBorder1 = new RightBorder();
  308. TopBorder topBorder1 = new TopBorder();
  309. BottomBorder bottomBorder1 = new BottomBorder();
  310. DiagonalBorder diagonalBorder1 = new DiagonalBorder();
  311.  
  312. border1.Append(leftBorder1);
  313. border1.Append(rightBorder1);
  314. border1.Append(topBorder1);
  315. border1.Append(bottomBorder1);
  316. border1.Append(diagonalBorder1);
  317.  
  318. borders1.Append(border1);
  319.  
  320. CellStyleFormats cellStyleFormats1 = new CellStyleFormats(){ Count = (UInt32Value)1U };
  321.  
  322. CellFormat cellFormat1 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U };
  323. Alignment alignment1 = new Alignment(){ Vertical = VerticalAlignmentValues.Center };
  324.  
  325. cellFormat1.Append(alignment1);
  326.  
  327. cellStyleFormats1.Append(cellFormat1);
  328.  
  329. CellFormats cellFormats1 = new CellFormats(){ Count = (UInt32Value)3U };
  330.  
  331. CellFormat cellFormat2 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U };
  332. Alignment alignment2 = new Alignment(){ Vertical = VerticalAlignmentValues.Center };
  333.  
  334. cellFormat2.Append(alignment2);
  335.  
  336. CellFormat cellFormat3 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)3U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true };
  337. Alignment alignment3 = new Alignment(){ Vertical = VerticalAlignmentValues.Center };
  338.  
  339. cellFormat3.Append(alignment3);
  340.  
  341. CellFormat cellFormat4 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)2U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyAlignment = true };
  342. Alignment alignment4 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Center, Vertical = VerticalAlignmentValues.Center };
  343.  
  344. cellFormat4.Append(alignment4);
  345.  
  346. cellFormats1.Append(cellFormat2);
  347. cellFormats1.Append(cellFormat3);
  348. cellFormats1.Append(cellFormat4);
  349.  
  350. CellStyles cellStyles1 = new CellStyles(){ Count = (UInt32Value)1U };
  351. CellStyle cellStyle1 = new CellStyle(){ Name = "常规", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U };
  352.  
  353. cellStyles1.Append(cellStyle1);
  354. DifferentialFormats differentialFormats1 = new DifferentialFormats(){ Count = (UInt32Value)0U };
  355. TableStyles tableStyles1 = new TableStyles(){ Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" };
  356.  
  357. StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList();
  358.  
  359. StylesheetExtension stylesheetExtension1 = new StylesheetExtension(){ Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" };
  360. stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
  361. X14.SlicerStyles slicerStyles1 = new X14.SlicerStyles(){ DefaultSlicerStyle = "SlicerStyleLight1" };
  362.  
  363. stylesheetExtension1.Append(slicerStyles1);
  364.  
  365. stylesheetExtensionList1.Append(stylesheetExtension1);
  366.  
  367. stylesheet1.Append(fonts1);
  368. stylesheet1.Append(fills1);
  369. stylesheet1.Append(borders1);
  370. stylesheet1.Append(cellStyleFormats1);
  371. stylesheet1.Append(cellFormats1);
  372. stylesheet1.Append(cellStyles1);
  373. stylesheet1.Append(differentialFormats1);
  374. stylesheet1.Append(tableStyles1);
  375. stylesheet1.Append(stylesheetExtensionList1);
  376.  
  377. workbookStylesPart1.Stylesheet = stylesheet1;
  378. }
  1. // Generates content of themePart1.
  2. private void GenerateThemePart1Content(ThemePart themePart1)
  3. {
  4. A.Theme theme1 = new A.Theme(){ Name = "Office 主题​​" };
  5. theme1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
  6.  
  7. A.ThemeElements themeElements1 = new A.ThemeElements();
  8.  
  9. A.ColorScheme colorScheme1 = new A.ColorScheme(){ Name = "Office" };
  10.  
  11. A.Dark1Color dark1Color1 = new A.Dark1Color();
  12. A.SystemColor systemColor1 = new A.SystemColor(){ Val = A.SystemColorValues.WindowText, LastColor = "000000" };
  13.  
  14. dark1Color1.Append(systemColor1);
  15.  
  16. A.Light1Color light1Color1 = new A.Light1Color();
  17. A.SystemColor systemColor2 = new A.SystemColor(){ Val = A.SystemColorValues.Window, LastColor = "FFFFFF" };
  18.  
  19. light1Color1.Append(systemColor2);
  20.  
  21. A.Dark2Color dark2Color1 = new A.Dark2Color();
  22. A.RgbColorModelHex rgbColorModelHex1 = new A.RgbColorModelHex(){ Val = "1F497D" };
  23.  
  24. dark2Color1.Append(rgbColorModelHex1);
  25.  
  26. A.Light2Color light2Color1 = new A.Light2Color();
  27. A.RgbColorModelHex rgbColorModelHex2 = new A.RgbColorModelHex(){ Val = "EEECE1" };
  28.  
  29. light2Color1.Append(rgbColorModelHex2);
  30.  
  31. A.Accent1Color accent1Color1 = new A.Accent1Color();
  32. A.RgbColorModelHex rgbColorModelHex3 = new A.RgbColorModelHex(){ Val = "4F81BD" };
  33.  
  34. accent1Color1.Append(rgbColorModelHex3);
  35.  
  36. A.Accent2Color accent2Color1 = new A.Accent2Color();
  37. A.RgbColorModelHex rgbColorModelHex4 = new A.RgbColorModelHex(){ Val = "C0504D" };
  38.  
  39. accent2Color1.Append(rgbColorModelHex4);
  40.  
  41. A.Accent3Color accent3Color1 = new A.Accent3Color();
  42. A.RgbColorModelHex rgbColorModelHex5 = new A.RgbColorModelHex(){ Val = "9BBB59" };
  43.  
  44. accent3Color1.Append(rgbColorModelHex5);
  45.  
  46. A.Accent4Color accent4Color1 = new A.Accent4Color();
  47. A.RgbColorModelHex rgbColorModelHex6 = new A.RgbColorModelHex(){ Val = "8064A2" };
  48.  
  49. accent4Color1.Append(rgbColorModelHex6);
  50.  
  51. A.Accent5Color accent5Color1 = new A.Accent5Color();
  52. A.RgbColorModelHex rgbColorModelHex7 = new A.RgbColorModelHex(){ Val = "4BACC6" };
  53.  
  54. accent5Color1.Append(rgbColorModelHex7);
  55.  
  56. A.Accent6Color accent6Color1 = new A.Accent6Color();
  57. A.RgbColorModelHex rgbColorModelHex8 = new A.RgbColorModelHex(){ Val = "F79646" };
  58.  
  59. accent6Color1.Append(rgbColorModelHex8);
  60.  
  61. A.Hyperlink hyperlink1 = new A.Hyperlink();
  62. A.RgbColorModelHex rgbColorModelHex9 = new A.RgbColorModelHex(){ Val = "0000FF" };
  63.  
  64. hyperlink1.Append(rgbColorModelHex9);
  65.  
  66. A.FollowedHyperlinkColor followedHyperlinkColor1 = new A.FollowedHyperlinkColor();
  67. A.RgbColorModelHex rgbColorModelHex10 = new A.RgbColorModelHex(){ Val = "800080" };
  68.  
  69. followedHyperlinkColor1.Append(rgbColorModelHex10);
  70.  
  71. colorScheme1.Append(dark1Color1);
  72. colorScheme1.Append(light1Color1);
  73. colorScheme1.Append(dark2Color1);
  74. colorScheme1.Append(light2Color1);
  75. colorScheme1.Append(accent1Color1);
  76. colorScheme1.Append(accent2Color1);
  77. colorScheme1.Append(accent3Color1);
  78. colorScheme1.Append(accent4Color1);
  79. colorScheme1.Append(accent5Color1);
  80. colorScheme1.Append(accent6Color1);
  81. colorScheme1.Append(hyperlink1);
  82. colorScheme1.Append(followedHyperlinkColor1);
  83.  
  84. A.FontScheme fontScheme4 = new A.FontScheme(){ Name = "Office" };
  85.  
  86. A.MajorFont majorFont1 = new A.MajorFont();
  87. A.LatinFont latinFont1 = new A.LatinFont(){ Typeface = "Cambria" };
  88. A.EastAsianFont eastAsianFont1 = new A.EastAsianFont(){ Typeface = "" };
  89. A.ComplexScriptFont complexScriptFont1 = new A.ComplexScriptFont(){ Typeface = "" };
  90. A.SupplementalFont supplementalFont1 = new A.SupplementalFont(){ Script = "Jpan", Typeface = "MS Pゴシック" };
  91. A.SupplementalFont supplementalFont2 = new A.SupplementalFont(){ Script = "Hang", Typeface = "맑은 고딕" };
  92. A.SupplementalFont supplementalFont3 = new A.SupplementalFont(){ Script = "Hans", Typeface = "宋体" };
  93. A.SupplementalFont supplementalFont4 = new A.SupplementalFont(){ Script = "Hant", Typeface = "新細明體" };
  94. A.SupplementalFont supplementalFont5 = new A.SupplementalFont(){ Script = "Arab", Typeface = "Times New Roman" };
  95. A.SupplementalFont supplementalFont6 = new A.SupplementalFont(){ Script = "Hebr", Typeface = "Times New Roman" };
  96. A.SupplementalFont supplementalFont7 = new A.SupplementalFont(){ Script = "Thai", Typeface = "Tahoma" };
  97. A.SupplementalFont supplementalFont8 = new A.SupplementalFont(){ Script = "Ethi", Typeface = "Nyala" };
  98. A.SupplementalFont supplementalFont9 = new A.SupplementalFont(){ Script = "Beng", Typeface = "Vrinda" };
  99. A.SupplementalFont supplementalFont10 = new A.SupplementalFont(){ Script = "Gujr", Typeface = "Shruti" };
  100. A.SupplementalFont supplementalFont11 = new A.SupplementalFont(){ Script = "Khmr", Typeface = "MoolBoran" };
  101. A.SupplementalFont supplementalFont12 = new A.SupplementalFont(){ Script = "Knda", Typeface = "Tunga" };
  102. A.SupplementalFont supplementalFont13 = new A.SupplementalFont(){ Script = "Guru", Typeface = "Raavi" };
  103. A.SupplementalFont supplementalFont14 = new A.SupplementalFont(){ Script = "Cans", Typeface = "Euphemia" };
  104. A.SupplementalFont supplementalFont15 = new A.SupplementalFont(){ Script = "Cher", Typeface = "Plantagenet Cherokee" };
  105. A.SupplementalFont supplementalFont16 = new A.SupplementalFont(){ Script = "Yiii", Typeface = "Microsoft Yi Baiti" };
  106. A.SupplementalFont supplementalFont17 = new A.SupplementalFont(){ Script = "Tibt", Typeface = "Microsoft Himalaya" };
  107. A.SupplementalFont supplementalFont18 = new A.SupplementalFont(){ Script = "Thaa", Typeface = "MV Boli" };
  108. A.SupplementalFont supplementalFont19 = new A.SupplementalFont(){ Script = "Deva", Typeface = "Mangal" };
  109. A.SupplementalFont supplementalFont20 = new A.SupplementalFont(){ Script = "Telu", Typeface = "Gautami" };
  110. A.SupplementalFont supplementalFont21 = new A.SupplementalFont(){ Script = "Taml", Typeface = "Latha" };
  111. A.SupplementalFont supplementalFont22 = new A.SupplementalFont(){ Script = "Syrc", Typeface = "Estrangelo Edessa" };
  112. A.SupplementalFont supplementalFont23 = new A.SupplementalFont(){ Script = "Orya", Typeface = "Kalinga" };
  113. A.SupplementalFont supplementalFont24 = new A.SupplementalFont(){ Script = "Mlym", Typeface = "Kartika" };
  114. A.SupplementalFont supplementalFont25 = new A.SupplementalFont(){ Script = "Laoo", Typeface = "DokChampa" };
  115. A.SupplementalFont supplementalFont26 = new A.SupplementalFont(){ Script = "Sinh", Typeface = "Iskoola Pota" };
  116. A.SupplementalFont supplementalFont27 = new A.SupplementalFont(){ Script = "Mong", Typeface = "Mongolian Baiti" };
  117. A.SupplementalFont supplementalFont28 = new A.SupplementalFont(){ Script = "Viet", Typeface = "Times New Roman" };
  118. A.SupplementalFont supplementalFont29 = new A.SupplementalFont(){ Script = "Uigh", Typeface = "Microsoft Uighur" };
  119. A.SupplementalFont supplementalFont30 = new A.SupplementalFont(){ Script = "Geor", Typeface = "Sylfaen" };
  120.  
  121. majorFont1.Append(latinFont1);
  122. majorFont1.Append(eastAsianFont1);
  123. majorFont1.Append(complexScriptFont1);
  124. majorFont1.Append(supplementalFont1);
  125. majorFont1.Append(supplementalFont2);
  126. majorFont1.Append(supplementalFont3);
  127. majorFont1.Append(supplementalFont4);
  128. majorFont1.Append(supplementalFont5);
  129. majorFont1.Append(supplementalFont6);
  130. majorFont1.Append(supplementalFont7);
  131. majorFont1.Append(supplementalFont8);
  132. majorFont1.Append(supplementalFont9);
  133. majorFont1.Append(supplementalFont10);
  134. majorFont1.Append(supplementalFont11);
  135. majorFont1.Append(supplementalFont12);
  136. majorFont1.Append(supplementalFont13);
  137. majorFont1.Append(supplementalFont14);
  138. majorFont1.Append(supplementalFont15);
  139. majorFont1.Append(supplementalFont16);
  140. majorFont1.Append(supplementalFont17);
  141. majorFont1.Append(supplementalFont18);
  142. majorFont1.Append(supplementalFont19);
  143. majorFont1.Append(supplementalFont20);
  144. majorFont1.Append(supplementalFont21);
  145. majorFont1.Append(supplementalFont22);
  146. majorFont1.Append(supplementalFont23);
  147. majorFont1.Append(supplementalFont24);
  148. majorFont1.Append(supplementalFont25);
  149. majorFont1.Append(supplementalFont26);
  150. majorFont1.Append(supplementalFont27);
  151. majorFont1.Append(supplementalFont28);
  152. majorFont1.Append(supplementalFont29);
  153. majorFont1.Append(supplementalFont30);
  154.  
  155. A.MinorFont minorFont1 = new A.MinorFont();
  156. A.LatinFont latinFont2 = new A.LatinFont(){ Typeface = "Calibri" };
  157. A.EastAsianFont eastAsianFont2 = new A.EastAsianFont(){ Typeface = "" };
  158. A.ComplexScriptFont complexScriptFont2 = new A.ComplexScriptFont(){ Typeface = "" };
  159. A.SupplementalFont supplementalFont31 = new A.SupplementalFont(){ Script = "Jpan", Typeface = "MS Pゴシック" };
  160. A.SupplementalFont supplementalFont32 = new A.SupplementalFont(){ Script = "Hang", Typeface = "맑은 고딕" };
  161. A.SupplementalFont supplementalFont33 = new A.SupplementalFont(){ Script = "Hans", Typeface = "宋体" };
  162. A.SupplementalFont supplementalFont34 = new A.SupplementalFont(){ Script = "Hant", Typeface = "新細明體" };
  163. A.SupplementalFont supplementalFont35 = new A.SupplementalFont(){ Script = "Arab", Typeface = "Arial" };
  164. A.SupplementalFont supplementalFont36 = new A.SupplementalFont(){ Script = "Hebr", Typeface = "Arial" };
  165. A.SupplementalFont supplementalFont37 = new A.SupplementalFont(){ Script = "Thai", Typeface = "Tahoma" };
  166. A.SupplementalFont supplementalFont38 = new A.SupplementalFont(){ Script = "Ethi", Typeface = "Nyala" };
  167. A.SupplementalFont supplementalFont39 = new A.SupplementalFont(){ Script = "Beng", Typeface = "Vrinda" };
  168. A.SupplementalFont supplementalFont40 = new A.SupplementalFont(){ Script = "Gujr", Typeface = "Shruti" };
  169. A.SupplementalFont supplementalFont41 = new A.SupplementalFont(){ Script = "Khmr", Typeface = "DaunPenh" };
  170. A.SupplementalFont supplementalFont42 = new A.SupplementalFont(){ Script = "Knda", Typeface = "Tunga" };
  171. A.SupplementalFont supplementalFont43 = new A.SupplementalFont(){ Script = "Guru", Typeface = "Raavi" };
  172. A.SupplementalFont supplementalFont44 = new A.SupplementalFont(){ Script = "Cans", Typeface = "Euphemia" };
  173. A.SupplementalFont supplementalFont45 = new A.SupplementalFont(){ Script = "Cher", Typeface = "Plantagenet Cherokee" };
  174. A.SupplementalFont supplementalFont46 = new A.SupplementalFont(){ Script = "Yiii", Typeface = "Microsoft Yi Baiti" };
  175. A.SupplementalFont supplementalFont47 = new A.SupplementalFont(){ Script = "Tibt", Typeface = "Microsoft Himalaya" };
  176. A.SupplementalFont supplementalFont48 = new A.SupplementalFont(){ Script = "Thaa", Typeface = "MV Boli" };
  177. A.SupplementalFont supplementalFont49 = new A.SupplementalFont(){ Script = "Deva", Typeface = "Mangal" };
  178. A.SupplementalFont supplementalFont50 = new A.SupplementalFont(){ Script = "Telu", Typeface = "Gautami" };
  179. A.SupplementalFont supplementalFont51 = new A.SupplementalFont(){ Script = "Taml", Typeface = "Latha" };
  180. A.SupplementalFont supplementalFont52 = new A.SupplementalFont(){ Script = "Syrc", Typeface = "Estrangelo Edessa" };
  181. A.SupplementalFont supplementalFont53 = new A.SupplementalFont(){ Script = "Orya", Typeface = "Kalinga" };
  182. A.SupplementalFont supplementalFont54 = new A.SupplementalFont(){ Script = "Mlym", Typeface = "Kartika" };
  183. A.SupplementalFont supplementalFont55 = new A.SupplementalFont(){ Script = "Laoo", Typeface = "DokChampa" };
  184. A.SupplementalFont supplementalFont56 = new A.SupplementalFont(){ Script = "Sinh", Typeface = "Iskoola Pota" };
  185. A.SupplementalFont supplementalFont57 = new A.SupplementalFont(){ Script = "Mong", Typeface = "Mongolian Baiti" };
  186. A.SupplementalFont supplementalFont58 = new A.SupplementalFont(){ Script = "Viet", Typeface = "Arial" };
  187. A.SupplementalFont supplementalFont59 = new A.SupplementalFont(){ Script = "Uigh", Typeface = "Microsoft Uighur" };
  188. A.SupplementalFont supplementalFont60 = new A.SupplementalFont(){ Script = "Geor", Typeface = "Sylfaen" };
  189.  
  190. minorFont1.Append(latinFont2);
  191. minorFont1.Append(eastAsianFont2);
  192. minorFont1.Append(complexScriptFont2);
  193. minorFont1.Append(supplementalFont31);
  194. minorFont1.Append(supplementalFont32);
  195. minorFont1.Append(supplementalFont33);
  196. minorFont1.Append(supplementalFont34);
  197. minorFont1.Append(supplementalFont35);
  198. minorFont1.Append(supplementalFont36);
  199. minorFont1.Append(supplementalFont37);
  200. minorFont1.Append(supplementalFont38);
  201. minorFont1.Append(supplementalFont39);
  202. minorFont1.Append(supplementalFont40);
  203. minorFont1.Append(supplementalFont41);
  204. minorFont1.Append(supplementalFont42);
  205. minorFont1.Append(supplementalFont43);
  206. minorFont1.Append(supplementalFont44);
  207. minorFont1.Append(supplementalFont45);
  208. minorFont1.Append(supplementalFont46);
  209. minorFont1.Append(supplementalFont47);
  210. minorFont1.Append(supplementalFont48);
  211. minorFont1.Append(supplementalFont49);
  212. minorFont1.Append(supplementalFont50);
  213. minorFont1.Append(supplementalFont51);
  214. minorFont1.Append(supplementalFont52);
  215. minorFont1.Append(supplementalFont53);
  216. minorFont1.Append(supplementalFont54);
  217. minorFont1.Append(supplementalFont55);
  218. minorFont1.Append(supplementalFont56);
  219. minorFont1.Append(supplementalFont57);
  220. minorFont1.Append(supplementalFont58);
  221. minorFont1.Append(supplementalFont59);
  222. minorFont1.Append(supplementalFont60);
  223.  
  224. fontScheme4.Append(majorFont1);
  225. fontScheme4.Append(minorFont1);
  226.  
  227. A.FormatScheme formatScheme1 = new A.FormatScheme(){ Name = "Office" };
  228.  
  229. A.FillStyleList fillStyleList1 = new A.FillStyleList();
  230.  
  231. A.SolidFill solidFill1 = new A.SolidFill();
  232. A.SchemeColor schemeColor1 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  233.  
  234. solidFill1.Append(schemeColor1);
  235.  
  236. A.GradientFill gradientFill1 = new A.GradientFill(){ RotateWithShape = true };
  237.  
  238. A.GradientStopList gradientStopList1 = new A.GradientStopList();
  239.  
  240. A.GradientStop gradientStop1 = new A.GradientStop(){ Position = 0 };
  241.  
  242. A.SchemeColor schemeColor2 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  243. A.Tint tint1 = new A.Tint(){ Val = 50000 };
  244. A.SaturationModulation saturationModulation1 = new A.SaturationModulation(){ Val = 300000 };
  245.  
  246. schemeColor2.Append(tint1);
  247. schemeColor2.Append(saturationModulation1);
  248.  
  249. gradientStop1.Append(schemeColor2);
  250.  
  251. A.GradientStop gradientStop2 = new A.GradientStop(){ Position = 35000 };
  252.  
  253. A.SchemeColor schemeColor3 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  254. A.Tint tint2 = new A.Tint(){ Val = 37000 };
  255. A.SaturationModulation saturationModulation2 = new A.SaturationModulation(){ Val = 300000 };
  256.  
  257. schemeColor3.Append(tint2);
  258. schemeColor3.Append(saturationModulation2);
  259.  
  260. gradientStop2.Append(schemeColor3);
  261.  
  262. A.GradientStop gradientStop3 = new A.GradientStop(){ Position = 100000 };
  263.  
  264. A.SchemeColor schemeColor4 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  265. A.Tint tint3 = new A.Tint(){ Val = 15000 };
  266. A.SaturationModulation saturationModulation3 = new A.SaturationModulation(){ Val = 350000 };
  267.  
  268. schemeColor4.Append(tint3);
  269. schemeColor4.Append(saturationModulation3);
  270.  
  271. gradientStop3.Append(schemeColor4);
  272.  
  273. gradientStopList1.Append(gradientStop1);
  274. gradientStopList1.Append(gradientStop2);
  275. gradientStopList1.Append(gradientStop3);
  276. A.LinearGradientFill linearGradientFill1 = new A.LinearGradientFill(){ Angle = 16200000, Scaled = true };
  277.  
  278. gradientFill1.Append(gradientStopList1);
  279. gradientFill1.Append(linearGradientFill1);
  280.  
  281. A.GradientFill gradientFill2 = new A.GradientFill(){ RotateWithShape = true };
  282.  
  283. A.GradientStopList gradientStopList2 = new A.GradientStopList();
  284.  
  285. A.GradientStop gradientStop4 = new A.GradientStop(){ Position = 0 };
  286.  
  287. A.SchemeColor schemeColor5 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  288. A.Shade shade1 = new A.Shade(){ Val = 51000 };
  289. A.SaturationModulation saturationModulation4 = new A.SaturationModulation(){ Val = 130000 };
  290.  
  291. schemeColor5.Append(shade1);
  292. schemeColor5.Append(saturationModulation4);
  293.  
  294. gradientStop4.Append(schemeColor5);
  295.  
  296. A.GradientStop gradientStop5 = new A.GradientStop(){ Position = 80000 };
  297.  
  298. A.SchemeColor schemeColor6 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  299. A.Shade shade2 = new A.Shade(){ Val = 93000 };
  300. A.SaturationModulation saturationModulation5 = new A.SaturationModulation(){ Val = 130000 };
  301.  
  302. schemeColor6.Append(shade2);
  303. schemeColor6.Append(saturationModulation5);
  304.  
  305. gradientStop5.Append(schemeColor6);
  306.  
  307. A.GradientStop gradientStop6 = new A.GradientStop(){ Position = 100000 };
  308.  
  309. A.SchemeColor schemeColor7 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  310. A.Shade shade3 = new A.Shade(){ Val = 94000 };
  311. A.SaturationModulation saturationModulation6 = new A.SaturationModulation(){ Val = 135000 };
  312.  
  313. schemeColor7.Append(shade3);
  314. schemeColor7.Append(saturationModulation6);
  315.  
  316. gradientStop6.Append(schemeColor7);
  317.  
  318. gradientStopList2.Append(gradientStop4);
  319. gradientStopList2.Append(gradientStop5);
  320. gradientStopList2.Append(gradientStop6);
  321. A.LinearGradientFill linearGradientFill2 = new A.LinearGradientFill(){ Angle = 16200000, Scaled = false };
  322.  
  323. gradientFill2.Append(gradientStopList2);
  324. gradientFill2.Append(linearGradientFill2);
  325.  
  326. fillStyleList1.Append(solidFill1);
  327. fillStyleList1.Append(gradientFill1);
  328. fillStyleList1.Append(gradientFill2);
  329.  
  330. A.LineStyleList lineStyleList1 = new A.LineStyleList();
  331.  
  332. A.Outline outline1 = new A.Outline(){ Width = 9525, CapType = A.LineCapValues.Flat, CompoundLineType = A.CompoundLineValues.Single, Alignment = A.PenAlignmentValues.Center };
  333.  
  334. A.SolidFill solidFill2 = new A.SolidFill();
  335.  
  336. A.SchemeColor schemeColor8 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  337. A.Shade shade4 = new A.Shade(){ Val = 95000 };
  338. A.SaturationModulation saturationModulation7 = new A.SaturationModulation(){ Val = 105000 };
  339.  
  340. schemeColor8.Append(shade4);
  341. schemeColor8.Append(saturationModulation7);
  342.  
  343. solidFill2.Append(schemeColor8);
  344. A.PresetDash presetDash1 = new A.PresetDash(){ Val = A.PresetLineDashValues.Solid };
  345.  
  346. outline1.Append(solidFill2);
  347. outline1.Append(presetDash1);
  348.  
  349. A.Outline outline2 = new A.Outline(){ Width = 25400, CapType = A.LineCapValues.Flat, CompoundLineType = A.CompoundLineValues.Single, Alignment = A.PenAlignmentValues.Center };
  350.  
  351. A.SolidFill solidFill3 = new A.SolidFill();
  352. A.SchemeColor schemeColor9 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  353.  
  354. solidFill3.Append(schemeColor9);
  355. A.PresetDash presetDash2 = new A.PresetDash(){ Val = A.PresetLineDashValues.Solid };
  356.  
  357. outline2.Append(solidFill3);
  358. outline2.Append(presetDash2);
  359.  
  360. A.Outline outline3 = new A.Outline(){ Width = 38100, CapType = A.LineCapValues.Flat, CompoundLineType = A.CompoundLineValues.Single, Alignment = A.PenAlignmentValues.Center };
  361.  
  362. A.SolidFill solidFill4 = new A.SolidFill();
  363. A.SchemeColor schemeColor10 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  364.  
  365. solidFill4.Append(schemeColor10);
  366. A.PresetDash presetDash3 = new A.PresetDash(){ Val = A.PresetLineDashValues.Solid };
  367.  
  368. outline3.Append(solidFill4);
  369. outline3.Append(presetDash3);
  370.  
  371. lineStyleList1.Append(outline1);
  372. lineStyleList1.Append(outline2);
  373. lineStyleList1.Append(outline3);
  374.  
  375. A.EffectStyleList effectStyleList1 = new A.EffectStyleList();
  376.  
  377. A.EffectStyle effectStyle1 = new A.EffectStyle();
  378.  
  379. A.EffectList effectList1 = new A.EffectList();
  380.  
  381. A.OuterShadow outerShadow1 = new A.OuterShadow(){ BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false };
  382.  
  383. A.RgbColorModelHex rgbColorModelHex11 = new A.RgbColorModelHex(){ Val = "000000" };
  384. A.Alpha alpha1 = new A.Alpha(){ Val = 38000 };
  385.  
  386. rgbColorModelHex11.Append(alpha1);
  387.  
  388. outerShadow1.Append(rgbColorModelHex11);
  389.  
  390. effectList1.Append(outerShadow1);
  391.  
  392. effectStyle1.Append(effectList1);
  393.  
  394. A.EffectStyle effectStyle2 = new A.EffectStyle();
  395.  
  396. A.EffectList effectList2 = new A.EffectList();
  397.  
  398. A.OuterShadow outerShadow2 = new A.OuterShadow(){ BlurRadius = 40000L, Distance = 23000L, Direction = 5400000, RotateWithShape = false };
  399.  
  400. A.RgbColorModelHex rgbColorModelHex12 = new A.RgbColorModelHex(){ Val = "000000" };
  401. A.Alpha alpha2 = new A.Alpha(){ Val = 35000 };
  402.  
  403. rgbColorModelHex12.Append(alpha2);
  404.  
  405. outerShadow2.Append(rgbColorModelHex12);
  406.  
  407. effectList2.Append(outerShadow2);
  408.  
  409. effectStyle2.Append(effectList2);
  410.  
  411. A.EffectStyle effectStyle3 = new A.EffectStyle();
  412.  
  413. A.EffectList effectList3 = new A.EffectList();
  414.  
  415. A.OuterShadow outerShadow3 = new A.OuterShadow(){ BlurRadius = 40000L, Distance = 23000L, Direction = 5400000, RotateWithShape = false };
  416.  
  417. A.RgbColorModelHex rgbColorModelHex13 = new A.RgbColorModelHex(){ Val = "000000" };
  418. A.Alpha alpha3 = new A.Alpha(){ Val = 35000 };
  419.  
  420. rgbColorModelHex13.Append(alpha3);
  421.  
  422. outerShadow3.Append(rgbColorModelHex13);
  423.  
  424. effectList3.Append(outerShadow3);
  425.  
  426. A.Scene3DType scene3DType1 = new A.Scene3DType();
  427.  
  428. A.Camera camera1 = new A.Camera(){ Preset = A.PresetCameraValues.OrthographicFront };
  429. A.Rotation rotation1 = new A.Rotation(){ Latitude = 0, Longitude = 0, Revolution = 0 };
  430.  
  431. camera1.Append(rotation1);
  432.  
  433. A.LightRig lightRig1 = new A.LightRig(){ Rig = A.LightRigValues.ThreePoints, Direction = A.LightRigDirectionValues.Top };
  434. A.Rotation rotation2 = new A.Rotation(){ Latitude = 0, Longitude = 0, Revolution = 1200000 };
  435.  
  436. lightRig1.Append(rotation2);
  437.  
  438. scene3DType1.Append(camera1);
  439. scene3DType1.Append(lightRig1);
  440.  
  441. A.Shape3DType shape3DType1 = new A.Shape3DType();
  442. A.BevelTop bevelTop1 = new A.BevelTop(){ Width = 63500L, Height = 25400L };
  443.  
  444. shape3DType1.Append(bevelTop1);
  445.  
  446. effectStyle3.Append(effectList3);
  447. effectStyle3.Append(scene3DType1);
  448. effectStyle3.Append(shape3DType1);
  449.  
  450. effectStyleList1.Append(effectStyle1);
  451. effectStyleList1.Append(effectStyle2);
  452. effectStyleList1.Append(effectStyle3);
  453.  
  454. A.BackgroundFillStyleList backgroundFillStyleList1 = new A.BackgroundFillStyleList();
  455.  
  456. A.SolidFill solidFill5 = new A.SolidFill();
  457. A.SchemeColor schemeColor11 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  458.  
  459. solidFill5.Append(schemeColor11);
  460.  
  461. A.GradientFill gradientFill3 = new A.GradientFill(){ RotateWithShape = true };
  462.  
  463. A.GradientStopList gradientStopList3 = new A.GradientStopList();
  464.  
  465. A.GradientStop gradientStop7 = new A.GradientStop(){ Position = 0 };
  466.  
  467. A.SchemeColor schemeColor12 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  468. A.Tint tint4 = new A.Tint(){ Val = 40000 };
  469. A.SaturationModulation saturationModulation8 = new A.SaturationModulation(){ Val = 350000 };
  470.  
  471. schemeColor12.Append(tint4);
  472. schemeColor12.Append(saturationModulation8);
  473.  
  474. gradientStop7.Append(schemeColor12);
  475.  
  476. A.GradientStop gradientStop8 = new A.GradientStop(){ Position = 40000 };
  477.  
  478. A.SchemeColor schemeColor13 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  479. A.Tint tint5 = new A.Tint(){ Val = 45000 };
  480. A.Shade shade5 = new A.Shade(){ Val = 99000 };
  481. A.SaturationModulation saturationModulation9 = new A.SaturationModulation(){ Val = 350000 };
  482.  
  483. schemeColor13.Append(tint5);
  484. schemeColor13.Append(shade5);
  485. schemeColor13.Append(saturationModulation9);
  486.  
  487. gradientStop8.Append(schemeColor13);
  488.  
  489. A.GradientStop gradientStop9 = new A.GradientStop(){ Position = 100000 };
  490.  
  491. A.SchemeColor schemeColor14 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  492. A.Shade shade6 = new A.Shade(){ Val = 20000 };
  493. A.SaturationModulation saturationModulation10 = new A.SaturationModulation(){ Val = 255000 };
  494.  
  495. schemeColor14.Append(shade6);
  496. schemeColor14.Append(saturationModulation10);
  497.  
  498. gradientStop9.Append(schemeColor14);
  499.  
  500. gradientStopList3.Append(gradientStop7);
  501. gradientStopList3.Append(gradientStop8);
  502. gradientStopList3.Append(gradientStop9);
  503.  
  504. A.PathGradientFill pathGradientFill1 = new A.PathGradientFill(){ Path = A.PathShadeValues.Circle };
  505. A.FillToRectangle fillToRectangle1 = new A.FillToRectangle(){ Left = 50000, Top = -80000, Right = 50000, Bottom = 180000 };
  506.  
  507. pathGradientFill1.Append(fillToRectangle1);
  508.  
  509. gradientFill3.Append(gradientStopList3);
  510. gradientFill3.Append(pathGradientFill1);
  511.  
  512. A.GradientFill gradientFill4 = new A.GradientFill(){ RotateWithShape = true };
  513.  
  514. A.GradientStopList gradientStopList4 = new A.GradientStopList();
  515.  
  516. A.GradientStop gradientStop10 = new A.GradientStop(){ Position = 0 };
  517.  
  518. A.SchemeColor schemeColor15 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  519. A.Tint tint6 = new A.Tint(){ Val = 80000 };
  520. A.SaturationModulation saturationModulation11 = new A.SaturationModulation(){ Val = 300000 };
  521.  
  522. schemeColor15.Append(tint6);
  523. schemeColor15.Append(saturationModulation11);
  524.  
  525. gradientStop10.Append(schemeColor15);
  526.  
  527. A.GradientStop gradientStop11 = new A.GradientStop(){ Position = 100000 };
  528.  
  529. A.SchemeColor schemeColor16 = new A.SchemeColor(){ Val = A.SchemeColorValues.PhColor };
  530. A.Shade shade7 = new A.Shade(){ Val = 30000 };
  531. A.SaturationModulation saturationModulation12 = new A.SaturationModulation(){ Val = 200000 };
  532.  
  533. schemeColor16.Append(shade7);
  534. schemeColor16.Append(saturationModulation12);
  535.  
  536. gradientStop11.Append(schemeColor16);
  537.  
  538. gradientStopList4.Append(gradientStop10);
  539. gradientStopList4.Append(gradientStop11);
  540.  
  541. A.PathGradientFill pathGradientFill2 = new A.PathGradientFill(){ Path = A.PathShadeValues.Circle };
  542. A.FillToRectangle fillToRectangle2 = new A.FillToRectangle(){ Left = 50000, Top = 50000, Right = 50000, Bottom = 50000 };
  543.  
  544. pathGradientFill2.Append(fillToRectangle2);
  545.  
  546. gradientFill4.Append(gradientStopList4);
  547. gradientFill4.Append(pathGradientFill2);
  548.  
  549. backgroundFillStyleList1.Append(solidFill5);
  550. backgroundFillStyleList1.Append(gradientFill3);
  551. backgroundFillStyleList1.Append(gradientFill4);
  552.  
  553. formatScheme1.Append(fillStyleList1);
  554. formatScheme1.Append(lineStyleList1);
  555. formatScheme1.Append(effectStyleList1);
  556. formatScheme1.Append(backgroundFillStyleList1);
  557.  
  558. themeElements1.Append(colorScheme1);
  559. themeElements1.Append(fontScheme4);
  560. themeElements1.Append(formatScheme1);
  561. A.ObjectDefaults objectDefaults1 = new A.ObjectDefaults();
  562. A.ExtraColorSchemeList extraColorSchemeList1 = new A.ExtraColorSchemeList();
  563.  
  564. theme1.Append(themeElements1);
  565. theme1.Append(objectDefaults1);
  566. theme1.Append(extraColorSchemeList1);
  567.  
  568. themePart1.Theme = theme1;
  569. }
  1. private void SetPackageProperties(OpenXmlPackage document)
  2. {
  3. document.PackageProperties.Creator = "Jim Tian";
  4. document.PackageProperties.Created = System.Xml.XmlConvert.ToDateTime("2015-01-27T07:53:29Z", System.Xml.XmlDateTimeSerializationMode.RoundtripKind);
  5. document.PackageProperties.Modified = System.Xml.XmlConvert.ToDateTime("2015-01-30T03:14:23Z", System.Xml.XmlDateTimeSerializationMode.RoundtripKind);
  6. document.PackageProperties.LastModifiedBy = "Jim Tian";
  7. }
  8.  
  9. #region Binary Data
  10. private string spreadsheetPrinterSettingsPart1Data = "XABcADEAOQAyAC4AMQA2ADgALgAzADAALgAyADIAMABcAEIAdQBpAGwAZABpAG4AZwAgAEEAIABJAFQAAAAAAAEEAAbcAPg0Q++ABwEACQCaCzQIZAABAA8AWAICAAEAWAIDAAEAQQA0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAABAAAAAgAAABQBAAD/////==";
  11.  
  12. private System.IO.Stream GetBinaryDataStream(string base64String)
  13. {
  14. return new System.IO.MemoryStream(System.Convert.FromBase64String(base64String));
  15. }
  16.  
  17. #endregion
  18.  
  19. }
  20. }
  1.  

步骤4、新建一个控制台应用程序,调用上述代码,生成自己新建的Excel

  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. string currentPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
  6. string filePath = Path.Combine(currentPath, "GeneratedPerson" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
  7.  
  8. GeneratedExcel54(filePath);
  9.  
  10. }
  11.  
  12. public static void GeneratedExcel(string filePath)
  13. {
  14. GeneratedClass gExcel = new GeneratedClass();
  15. gExcel.CreatePackage(filePath);
  16. }
  17.  
  18. }

步骤5、动态添加自己的数据

5.1 、修改函数(目标是为了添加数据, 所以移动了这个sharedStringTablePart 的位置,其次为了调用sharedStringTablePart 给GenerateWorksheetPart3Content 函数增加了参数, 便于添加数据

  1.  
  1. // Adds child parts and generates content of the specified part.
  2. private void CreateParts(SpreadsheetDocument document)
  3. {
  4. ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3");
  5. GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1);
  6.  
  7. WorkbookPart workbookPart1 = document.AddWorkbookPart();
  8. GenerateWorkbookPart1Content(workbookPart1);

SharedStringTablePart shareStringPart = workbookPart1.AddNewPart<SharedStringTablePart>("rId6"); // GenerateSharedStringTablePart1Content(shareStringPart);

  1. WorksheetPart worksheetPart1 = workbookPart1.AddNewPart<WorksheetPart>("rId3");
  2. GenerateWorksheetPart1Content(worksheetPart1);
  3.  
  4. WorksheetPart worksheetPart2 = workbookPart1.AddNewPart<WorksheetPart>("rId2");
  5. GenerateWorksheetPart2Content(worksheetPart2);
  6.  
  7. WorksheetPart worksheetPart3 = workbookPart1.AddNewPart<WorksheetPart>("rId1");

GenerateWorksheetPart3Content(worksheetPart3, shareStringPart);

  1. SpreadsheetPrinterSettingsPart spreadsheetPrinterSettingsPart1 = worksheetPart3.AddNewPart<SpreadsheetPrinterSettingsPart>("rId1");
  2. GenerateSpreadsheetPrinterSettingsPart1Content(spreadsheetPrinterSettingsPart1);
  3.  
  4. WorkbookStylesPart workbookStylesPart1 = workbookPart1.AddNewPart<WorkbookStylesPart>("rId5");
  5. GenerateWorkbookStylesPart1Content(workbookStylesPart1);
  6.  
  7. ThemePart themePart1 = workbookPart1.AddNewPart<ThemePart>("rId4");
  8. GenerateThemePart1Content(themePart1);
  9.  
  10. SetPackageProperties(document);
  11. }
  1.  

5.2 、动态添加数据

  1. // Generates content of worksheetPart3.
  2. private void GenerateWorksheetPart3Content(WorksheetPart worksheetPart3, SharedStringTablePart shareStringPart)
  3. {
  4. Worksheet worksheet3 = new Worksheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } };
  5. worksheet3.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
  6. worksheet3.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
  7. worksheet3.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
  8. SheetDimension sheetDimension3 = new SheetDimension() { Reference = "A1:D2" };
  9.  
  10. SheetViews sheetViews3 = new SheetViews();
  11.  
  12. SheetView sheetView3 = new SheetView() { TabSelected = true, WorkbookViewId = (UInt32Value)0U };
  13. Selection selection1 = new Selection() { ActiveCell = "A2", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "A2:D2" } };
  14.  
  15. sheetView3.Append(selection1);
  16.  
  17. sheetViews3.Append(sheetView3);
  18. SheetFormatProperties sheetFormatProperties3 = new SheetFormatProperties() { DefaultRowHeight = 13.5D, DyDescent = 0.15D };
  19.  
  20. Columns columns1 = new Columns();
  21. Column column1 = new Column() { Min = (UInt32Value)1U, Max = (UInt32Value)1U, Width = 25.25D, CustomWidth = true };
  22. Column column2 = new Column() { Min = (UInt32Value)2U, Max = (UInt32Value)2U, Width = 35D, CustomWidth = true };
  23. Column column3 = new Column() { Min = (UInt32Value)3U, Max = (UInt32Value)3U, Width = 20.125D, CustomWidth = true };
  24. Column column4 = new Column() { Min = (UInt32Value)4U, Max = (UInt32Value)4U, Width = 100.75D, CustomWidth = true };
  25.  
  26. columns1.Append(column1);
  27. columns1.Append(column2);
  28. columns1.Append(column3);
  29. columns1.Append(column4);
  30.  
  31. SheetData sheetData3 = new SheetData();
  32.  
  33. Row row1 = new Row() { RowIndex = (UInt32Value)1U, Spans = new ListValue<StringValue>() { InnerText = "1:4" }, Height = 24D, CustomHeight = true, DyDescent = 0.15D };
  34.  
  35. //Cell cell1 = new Cell(){ CellReference = "A1", StyleIndex = (UInt32Value)1U, DataType = CellValues.SharedString };
  36. //CellValue cellValue1 = new CellValue();
  37. //cellValue1.Text = "0";
  38.  
  39. Cell cell1 = CreateCell("用户信息列表", shareStringPart);
  40. cell1.StyleIndex = (UInt32Value)1U;
  41.  
  42. Cell cell2 = new Cell() { CellReference = "B1", StyleIndex = (UInt32Value)1U };
  43. Cell cell3 = new Cell() { CellReference = "C1", StyleIndex = (UInt32Value)1U };
  44. Cell cell4 = new Cell() { CellReference = "D1", StyleIndex = (UInt32Value)1U };
  45.  
  46. row1.Append(cell1);
  47. row1.Append(cell2);
  48. row1.Append(cell3);
  49. row1.Append(cell4);
  50. sheetData3.Append(row1);
  51.  
  52. #region 添加数据

ExcelDataUtil dataUtil = new ExcelDataUtil(); dataUtil.ExcelData = DataUtil.GetExcelData(); Dictionary<string, string> mDict = new Dictionary<string, string>(); mDict.Add("CustomerID", "用户编号"); mDict.Add("CompanyName", "公司名称"); mDict.Add("ContactTitle", "联系标题"); mDict.Add("ContactName", "联系人名称"); dataUtil.HeaderDict = mDict; AddDataToSheet(dataUtil, shareStringPart, sheetData3);

  1. #endregion
  2.  
  3. MergeCells mergeCells1 = new MergeCells() { Count = (UInt32Value)1U };
  4. MergeCell mergeCell1 = new MergeCell() { Reference = "A1:D1" };
  5.  
  6. mergeCells1.Append(mergeCell1);
  7. PhoneticProperties phoneticProperties3 = new PhoneticProperties() { FontId = (UInt32Value)1U, Type = PhoneticValues.NoConversion };
  8. PageMargins pageMargins3 = new PageMargins() { Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D };
  9. PageSetup pageSetup1 = new PageSetup() { PaperSize = (UInt32Value)9U, Orientation = OrientationValues.Portrait, Id = "rId1" };
  10.  
  11. worksheet3.Append(sheetDimension3);
  12. worksheet3.Append(sheetViews3);
  13. worksheet3.Append(sheetFormatProperties3);
  14. worksheet3.Append(columns1);
  15. worksheet3.Append(sheetData3);
  16. worksheet3.Append(mergeCells1);
  17. worksheet3.Append(phoneticProperties3);
  18. worksheet3.Append(pageMargins3);
  19. worksheet3.Append(pageSetup1);
  20.  
  21. worksheetPart3.Worksheet = worksheet3;
  22. }
  1.  

5.3 、为添加数据,需要提供AddDataToSheet(dataUtil, shareStringPart, sheetData3) 函数的实现即可

  1. public class ExcelHelper
  2. {
  3. /// <summary>
  4. /// 创建Excel示例
  5. /// </summary>
  6. /// <param name="fileName">Excel 文件名称</param>
  7. public void CreateSpreadSheet(string fileName)
  8. {
  9.  
  10. string sheetName = "test";
  11.  
  12. using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook))
  13. {
  14. // create the workbook
  15. spreadSheet.AddWorkbookPart();
  16. spreadSheet.WorkbookPart.Workbook = new Workbook(); // create the worksheet
  17. spreadSheet.WorkbookPart.AddNewPart<WorksheetPart>();
  18. spreadSheet.WorkbookPart.WorksheetParts.First().Worksheet = new Worksheet();
  19. SharedStringTablePart m_SharedStringTablePart = spreadSheet.WorkbookPart.AddNewPart<SharedStringTablePart>();
  20.  
  21. // create sheet data
  22. SheetData m_SheetData = new SheetData();
  23. spreadSheet.WorkbookPart.WorksheetParts.First().Worksheet.AppendChild(m_SheetData);
  24.  
  25. // create row
  26. //spreadSheet.WorkbookPart.WorksheetParts.First().Worksheet.First().AppendChild(new Row());
  27. //// create cell with data
  28. //spreadSheet.WorkbookPart.WorksheetParts.First().Worksheet.First().First().AppendChild(new Cell() { CellValue = new CellValue("100") });
  29.  
  30. //Add Data
  31. Row row1 = new Row() { RowIndex = 1 };
  32.  
  33. Cell cell1 = new Cell() { CellReference = "A1" };
  34. int index = InsertSharedStringItem("Sun", m_SharedStringTablePart);
  35. cell1.CellValue = new CellValue(index.ToString());
  36. cell1.DataType = new EnumValue<CellValues>(CellValues.SharedString);
  37.  
  38. row1.Append(cell1);
  39. m_SheetData.Append(row1);
  40.  
  41. // save worksheet
  42. spreadSheet.WorkbookPart.WorksheetParts.First().Worksheet.Save();
  43.  
  44. // create the worksheet to workbook relation
  45. spreadSheet.WorkbookPart.Workbook.AppendChild(new Sheets());
  46. spreadSheet.WorkbookPart.Workbook.GetFirstChild<Sheets>().AppendChild(new Sheet()
  47. {
  48. Id = spreadSheet.WorkbookPart.GetIdOfPart(spreadSheet.WorkbookPart.WorksheetParts.First()),
  49. SheetId = 1,
  50. Name = sheetName
  51. });
  52.  
  53. spreadSheet.WorkbookPart.Workbook.Save();
  54. }
  55. }
  56.  
  57. /// <summary>
  58. /// 添加数据
  59. /// </summary>
  60. /// <param name="text"></param>
  61. /// <param name="shareStringPart"></param>
  62. /// <returns></returns>
  63. protected int InsertSharedStringItem(string text, SharedStringTablePart shareStringPart)
  64. {
  65. // If the part does not contain a SharedStringTable, create one.
  66. if (shareStringPart.SharedStringTable == null)
  67. {
  68. shareStringPart.SharedStringTable = new SharedStringTable();
  69. shareStringPart.SharedStringTable.Count = 1;
  70. shareStringPart.SharedStringTable.UniqueCount = 1;
  71. }
  72.  
  73. // SharedStringTable is contained in this part, you can add one.
  74. shareStringPart.SharedStringTable.Count += 1;
  75.  
  76. int i = 0;
  77. // Iterate through all the items in the SharedStringTable. If the text already exists, return its index.
  78. foreach (SharedStringItem item in shareStringPart.SharedStringTable.Elements<SharedStringItem>())
  79. {
  80. if (item.InnerText == text)
  81. {
  82. return i;
  83. }
  84. i++;
  85. }
  86.  
  87. // The text does not exist in the part. Create the SharedStringItem and return its index.
  88. shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new DocumentFormat.OpenXml.Spreadsheet.Text(text)));
  89.  
  90. //PhoneticProperties phoneticProperties = new PhoneticProperties() { FontId = (UInt32Value)1U, Type = PhoneticValues.NoConversion };
  91. //shareStringPart.SharedStringTable.AppendChild(phoneticProperties);
  92.  
  93. shareStringPart.SharedStringTable.UniqueCount += 1;
  94. shareStringPart.SharedStringTable.Save();
  95.  
  96. return i;
  97. }
  98.  
  99. protected Cell CreateCell(string txtContent, SharedStringTablePart shareStringPart, UInt32Value styleIndex = null )
  100. {
  101. Cell mCell = new Cell();
  102. mCell.StyleIndex = styleIndex;
  103. int index = InsertSharedStringItem(txtContent, shareStringPart);
  104. CellValue mCellVal = new CellValue(index.ToString());
  105. mCell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
  106. mCell.Append(mCellVal);
  107. return mCell;
  108. }
  109.  
  110. /// <summary>
  111. /// 添加数据到Excel 中
  112. /// </summary>
  113. /// <param name="dt"></param>
  114. /// <param name="mHeaderDict"></param>
  115. /// <param name="sheetData"></param>
  116. protected void AddDataToSheet(ExcelDataUtil excelUtil, SharedStringTablePart shareStringPart, SheetData sheetData)
  117. {
  118. if(excelUtil.ExcelData != null && excelUtil.HeaderDict != null)
  119. {
  120. UInt32Value startRowNo = 2;
  121. if(excelUtil.HeaderDict.Count > 0)
  122. {
  123. // 添加列头信息
  124. Row rowHeader = new Row() { RowIndex = startRowNo, Spans = new ListValue<StringValue>() { InnerText =string.Format("1:{0}", excelUtil.HeaderDict.Count) /*"1:4"*/ }, Height = 15.75D, DyDescent = 0.15D };
  125. foreach(var item in excelUtil.HeaderDict)
  126. {
  127. Cell mCell = CreateCell(item.Value, shareStringPart, (UInt32Value)2U);
  128. rowHeader.Append(mCell);
  129. }
  130. sheetData.Append(rowHeader);
  131. startRowNo++;
  132. }
  133.  
  134. foreach (DataRow dr in excelUtil.ExcelData.Rows)
  135. {
  136. Row rowContent = new Row() { RowIndex = startRowNo, Spans = new ListValue<StringValue>() { InnerText =string.Format("1:{0}", excelUtil.HeaderDict.Count) /*"1:4"*/ }, Height = 15.75D, DyDescent = 0.15D };
  137. foreach (var item in excelUtil.HeaderDict)
  138. {
  139. Cell mCell = CreateCell(dr[item.Key].ToString(), shareStringPart, (UInt32Value)0U);
  140. rowContent.Append(mCell);
  141. }
  142. sheetData.Append(rowContent);
  143. startRowNo++;
  144. }
  145. }
  146.  
  147. }
  148.  
  149. }
  1.  
  1. 5.4 可以让生成的GeneratedClass 继承ExcelHelper类,实现添加Excel 数据功能的可复用性
  1.  
  1. 本文的源码

基于Open XML 导出数据到Excel的更多相关文章

  1. asp.net使用MVC4框架基于NPOI做导出数据到Excel表

    NPOI 是 POI 项目的 .NET 版本.POI是一个开源的Java读写Excel.WORD等微软OLE2组件文档的项目. 使用 NPOI 你就可以在没有安装 Office 或者相应环境的机器上对 ...

  2. 使用Open xml 操作Excel系列之二--从data table导出数据到Excel

    由于Excel中提供了透视表PivotTable,许多项目都使用它来作为数据分析报表. 在有些情况下,我们需要在Excel中设计好模板,包括数据源表,透视表等, 当数据导入到数据源表时,自动更新透视表 ...

  3. 导出数据到Excel方法总结

    一,问题的提出 近来在网上经常有人问怎样把数据导出到Excel中?针对这个问题网上也有很多资料.大都比较的琐碎.本人当前从事的项目中,刚好涉及到这些内容.就顺便做了一些归纳整理.共享给大家.避免大家再 ...

  4. 1.ASP.NET MVC使用EPPlus,导出数据到Excel中

    好久没写博客了,今天特地来更新一下,今天我们要学习的是如何导出数据到Excel文件中,这里我使用的是免费开源的Epplus组件. 源代码下载:https://github.com/caofangshe ...

  5. 导出数据到Excel --使用ExcelReport有感

    先看图,这是几个月前用NPOI写的导出数据到Excel,用了上百行代码,而且难控制,导出来也比较难看 excel打开的效果 下面是我用ExcelReport类库导出到Excel的操作 1.首先引用Ex ...

  6. php导出数据到excel,防止身份证等数字字符格式变成科学计数的方法

    而关于php的也有,但是大多都是用phpExcel导出的方法或者spreadsheet等类或者控件之类的导出方法,而我所在维护的系统却用很简单的方法,如下,网上很少有讲如何设置要导出数据的EXcel格 ...

  7. C#导出数据到Excel通用的方法类

    导出数据到Excel通用的方法类,请应对需求自行修改. 资源下载列表 using System.Data; using System.IO; namespace IM.Common.Tools { p ...

  8. pl/sql developer导出数据到excel的方法

    http://yedward.net/?id=92 问题说明:使用pl/sql developer导出数据到excel表格中是非常有必要的,一般的可能直接在导出的时候选择csv格式即可,因为该格式可以 ...

  9. Dynamics CRM导出数据到Excel

    原创地址:http://www.cnblogs.com/jfzhu/p/4276212.html 转载请注明出处 Pivot Table是微软BI的一个重要工具,所以这里讲一下Dynamics CRM ...

随机推荐

  1. django的cache

    使用文件缓存 #settings.py   CACHES = {   'default': {   'BACKEND': 'django.core.cache.backends.filebased.F ...

  2. 【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

    1. 错误描述 今天在Android Studio中,使用gradle命令的时候,出现了如下所示的错误: D:\GitLab Source\XTCLint>gradlew clean uploa ...

  3. Mirror--镜像相关操作

    其他相关操作1. 关闭镜像--关闭镜像USE [master]GOALTER DATABASE Demo1 SET PARTNER OFFGO  2. 证服务器--移除见证服务器USE [master ...

  4. android GridView的setOnItemClickListener事件不执行

    问题可能1: item设置的可能是button,或者可以click点击事件控件,导致控件执行而item按钮不执行 解决方法:设置控件 的  android:clickable="false& ...

  5. 6.安装pyhook报错is not a supported wheel on this platform

    解决方法: 先找到合适的格式: 然后,选择合适的版本: 安装即可成功:

  6. C#+GDAL读取影像(1)

    环境:VS2010,C#,GDAL1.7 读取影像: using System; using System.Collections.Generic; using System.ComponentMod ...

  7. Spark checkpoint机制简述

    本文主要简述spark checkpoint机制,快速把握checkpoint机制的来龙去脉,至于源码可以参考我的下一篇文章. 1.Spark core的checkpoint 1)为什么checkpo ...

  8. CSS控制列表样式属性list-style有哪些?怎么用?

    CSS列表样式属性list-style有哪些类型?不同类型CSS控制列表样式使用时该注意什么? 这是W3Cschool用户Shirley于2016-11-10在W3Cschool编程问答提出的问题.云 ...

  9. html结构和标签

    <!DOCTYPE html><meta charset="utf-8"><header>表示页面的一个内容区块,或整个页面的标题</he ...

  10. Entity Framework 并发处理(转)

    什么是并发? 并发分悲观并发和乐观并发. 悲观并发:比如有两个用户A,B,同时登录系统修改一个文档,如果A先进入修改,则系统会把该文档锁住,B就没办法打开了,只有等A修改完,完全退出的时候B才能进入修 ...