Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using DocumentFormat.OpenXml.Packaging;
- using Ap = DocumentFormat.OpenXml.ExtendedProperties;
- using Vt = DocumentFormat.OpenXml.VariantTypes;
- using DocumentFormat.OpenXml;
- using DocumentFormat.OpenXml.Spreadsheet;
- using X15ac = DocumentFormat.OpenXml.Office2013.ExcelAc;
- using X15 = DocumentFormat.OpenXml.Office2013.Excel;
- using X14 = DocumentFormat.OpenXml.Office2010.Excel;
- using A = DocumentFormat.OpenXml.Drawing;
- using Thm15 = DocumentFormat.OpenXml.Office2013.Theme;
- namespace GeneratedCode
- {
- public class GeneratedClass
- {
- // Creates a SpreadsheetDocument.
- public void CreatePackage(string filePath)
- {
- using (SpreadsheetDocument document = SpreadsheetDocument.Create(filePath, SpreadsheetDocumentType.Workbook))
- {
- WorkbookPart workbookPart1 = document.AddWorkbookPart();
- GenerateWorkbookPart1Content(workbookPart1);
- WorksheetPart worksheetPart1 = workbookPart1.AddNewPart<WorksheetPart>("rId1");
- GenerateWorksheetPart1Content(worksheetPart1);
- TableDefinitionPart tableDefinitionPart1 = worksheetPart1.AddNewPart<TableDefinitionPart>("rId1");
- GenerateTableDefinitionPart1Content(tableDefinitionPart1, worksheetPart1.Worksheet);
- SharedStringTablePart sharedStringTablePart1 = workbookPart1.AddNewPart<SharedStringTablePart>("rId4");
- GenerateSharedStringTablePart1Content(sharedStringTablePart1);
- }
- }
- // Generates content of workbookPart1.
- private void GenerateWorkbookPart1Content(WorkbookPart workbookPart1)
- {
- Workbook workbook1 = new Workbook() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x15" } };
- workbook1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
- workbook1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
- workbook1.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
- FileVersion fileVersion1 = new FileVersion() { ApplicationName = "xl", LastEdited = "6", LowestEdited = "6", BuildVersion = "14420" };
- WorkbookProperties workbookProperties1 = new WorkbookProperties() { DefaultThemeVersion = (UInt32Value)153222U };
- AlternateContent alternateContent1 = new AlternateContent();
- alternateContent1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
- AlternateContentChoice alternateContentChoice1 = new AlternateContentChoice() { Requires = "x15" };
- X15ac.AbsolutePath absolutePath1 = new X15ac.AbsolutePath() { Url = "C:\\Users\\leand_000\\Desktop\\" };
- absolutePath1.AddNamespaceDeclaration("x15ac", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac");
- alternateContentChoice1.Append(absolutePath1);
- alternateContent1.Append(alternateContentChoice1);
- BookViews bookViews1 = new BookViews();
- WorkbookView workbookView1 = new WorkbookView() { XWindow = 0, YWindow = 0, WindowWidth = (UInt32Value)20490U, WindowHeight = (UInt32Value)8340U };
- bookViews1.Append(workbookView1);
- Sheets sheets1 = new Sheets();
- Sheet sheet1 = new Sheet() { Name = "Sheet1", SheetId = (UInt32Value)1U, Id = "rId1" };
- sheets1.Append(sheet1);
- CalculationProperties calculationProperties1 = new CalculationProperties() { CalculationId = (UInt32Value)152511U };
- WorkbookExtensionList workbookExtensionList1 = new WorkbookExtensionList();
- WorkbookExtension workbookExtension1 = new WorkbookExtension() { Uri = "{140A7094-0E35-4892-8432-C4D2E57EDEB5}" };
- workbookExtension1.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
- X15.WorkbookProperties workbookProperties2 = new X15.WorkbookProperties() { ChartTrackingReferenceBase = true };
- workbookExtension1.Append(workbookProperties2);
- workbookExtensionList1.Append(workbookExtension1);
- workbook1.Append(fileVersion1);
- workbook1.Append(workbookProperties1);
- workbook1.Append(alternateContent1);
- workbook1.Append(bookViews1);
- workbook1.Append(sheets1);
- workbook1.Append(calculationProperties1);
- workbook1.Append(workbookExtensionList1);
- workbookPart1.Workbook = workbook1;
- }
- // Generates content of worksheetPart1.
- private void GenerateWorksheetPart1Content(WorksheetPart worksheetPart1)
- {
- Worksheet worksheet1 = new Worksheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } };
- worksheet1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
- worksheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
- worksheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
- SheetDimension sheetDimension1 = new SheetDimension() { Reference = "A2:C5" };
- SheetViews sheetViews1 = new SheetViews();
- SheetView sheetView1 = new SheetView() { TabSelected = true, WorkbookViewId = (UInt32Value)0U };
- Selection selection1 = new Selection() { ActiveCell = "F6", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "F6" } };
- sheetView1.Append(selection1);
- sheetViews1.Append(sheetView1);
- SheetFormatProperties sheetFormatProperties1 = new SheetFormatProperties() { DefaultRowHeight = 15D, DyDescent = 0.25D };
- SheetData sheetData1 = new SheetData();
- Row row1 = new Row() { RowIndex = (UInt32Value)2U, Spans = new ListValue<StringValue>() { InnerText = "1:3" }, DyDescent = 0.25D };
- Cell cell1 = new Cell() { CellReference = "A2", DataType = CellValues.SharedString };
- CellValue cellValue1 = new CellValue();
- cellValue1.Text = "0";
- cell1.Append(cellValue1);
- Cell cell2 = new Cell() { CellReference = "B2", DataType = CellValues.SharedString };
- CellValue cellValue2 = new CellValue();
- cellValue2.Text = "1";
- cell2.Append(cellValue2);
- Cell cell3 = new Cell() { CellReference = "C2", DataType = CellValues.SharedString };
- CellValue cellValue3 = new CellValue();
- cellValue3.Text = "2";
- cell3.Append(cellValue3);
- row1.Append(cell1);
- row1.Append(cell2);
- row1.Append(cell3);
- Row row2 = new Row() { RowIndex = (UInt32Value)3U, Spans = new ListValue<StringValue>() { InnerText = "1:3" }, DyDescent = 0.25D };
- Cell cell4 = new Cell() { CellReference = "A3" };
- CellValue cellValue4 = new CellValue();
- cellValue4.Text = "22";
- cell4.Append(cellValue4);
- Cell cell5 = new Cell() { CellReference = "B3", DataType = CellValues.SharedString };
- CellValue cellValue5 = new CellValue();
- cellValue5.Text = "3";
- cell5.Append(cellValue5);
- Cell cell6 = new Cell() { CellReference = "C3", DataType = CellValues.SharedString };
- CellValue cellValue6 = new CellValue();
- cellValue6.Text = "6";
- cell6.Append(cellValue6);
- row2.Append(cell4);
- row2.Append(cell5);
- row2.Append(cell6);
- Row row3 = new Row() { RowIndex = (UInt32Value)4U, Spans = new ListValue<StringValue>() { InnerText = "1:3" }, DyDescent = 0.25D };
- Cell cell7 = new Cell() { CellReference = "A4" };
- CellValue cellValue7 = new CellValue();
- cellValue7.Text = "3";
- cell7.Append(cellValue7);
- Cell cell8 = new Cell() { CellReference = "B4", DataType = CellValues.SharedString };
- CellValue cellValue8 = new CellValue();
- cellValue8.Text = "4";
- cell8.Append(cellValue8);
- Cell cell9 = new Cell() { CellReference = "C4", DataType = CellValues.SharedString };
- CellValue cellValue9 = new CellValue();
- cellValue9.Text = "7";
- cell9.Append(cellValue9);
- row3.Append(cell7);
- row3.Append(cell8);
- row3.Append(cell9);
- Row row4 = new Row() { RowIndex = (UInt32Value)5U, Spans = new ListValue<StringValue>() { InnerText = "1:3" }, DyDescent = 0.25D };
- Cell cell10 = new Cell() { CellReference = "A5" };
- CellValue cellValue10 = new CellValue();
- cellValue10.Text = "45";
- cell10.Append(cellValue10);
- Cell cell11 = new Cell() { CellReference = "B5", DataType = CellValues.SharedString };
- CellValue cellValue11 = new CellValue();
- cellValue11.Text = "5";
- cell11.Append(cellValue11);
- Cell cell12 = new Cell() { CellReference = "C5", DataType = CellValues.SharedString };
- CellValue cellValue12 = new CellValue();
- cellValue12.Text = "8";
- cell12.Append(cellValue12);
- row4.Append(cell10);
- row4.Append(cell11);
- row4.Append(cell12);
- sheetData1.Append(row1);
- sheetData1.Append(row2);
- sheetData1.Append(row3);
- sheetData1.Append(row4);
- PageMargins pageMargins1 = new PageMargins() { Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D };
- worksheet1.Append(sheetDimension1);
- worksheet1.Append(sheetViews1);
- worksheet1.Append(sheetFormatProperties1);
- worksheet1.Append(sheetData1);
- worksheet1.Append(pageMargins1);
- //worksheet1.Append(tableParts1);
- worksheetPart1.Worksheet = worksheet1;
- }
- // Generates content of tableDefinitionPart1.
- private void GenerateTableDefinitionPart1Content(TableDefinitionPart tableDefinitionPart1, Worksheet worksheet1)
- {
- TableParts tableParts1 = new TableParts() { Count = (UInt32Value)1U };
- TablePart tablePart1 = new TablePart() { Id = "rId1" };
- tableParts1.Append(tablePart1);
- worksheet1.Append(tableParts1);
- Table table1 = new Table() { Id = (UInt32Value)2U, Name = "Table2", DisplayName = "Table2", Reference = "A2:C5", TotalsRowShown = false };
- AutoFilter autoFilter1 = new AutoFilter() { Reference = "A2:C5" };
- TableColumns tableColumns1 = new TableColumns() { Count = (UInt32Value)3U };
- TableColumn tableColumn1 = new TableColumn() { Id = (UInt32Value)1U, Name = "a" };
- TableColumn tableColumn2 = new TableColumn() { Id = (UInt32Value)2U, Name = "b" };
- TableColumn tableColumn3 = new TableColumn() { Id = (UInt32Value)3U, Name = "c" };
- tableColumns1.Append(tableColumn1);
- tableColumns1.Append(tableColumn2);
- tableColumns1.Append(tableColumn3);
- TableStyleInfo tableStyleInfo1 = new TableStyleInfo() { Name = "TableStyleMedium2", ShowFirstColumn = false, ShowLastColumn = false, ShowRowStripes = true, ShowColumnStripes = false };
- table1.Append(autoFilter1);
- table1.Append(tableColumns1);
- table1.Append(tableStyleInfo1);
- tableDefinitionPart1.Table = table1;
- }
- // Generates content of sharedStringTablePart1.
- private void GenerateSharedStringTablePart1Content(SharedStringTablePart sharedStringTablePart1)
- {
- SharedStringTable sharedStringTable1 = new SharedStringTable() { Count = (UInt32Value)9U, UniqueCount = (UInt32Value)9U };
- SharedStringItem sharedStringItem1 = new SharedStringItem();
- Text text1 = new Text();
- text1.Text = "a";
- sharedStringItem1.Append(text1);
- SharedStringItem sharedStringItem2 = new SharedStringItem();
- Text text2 = new Text();
- text2.Text = "b";
- sharedStringItem2.Append(text2);
- SharedStringItem sharedStringItem3 = new SharedStringItem();
- Text text3 = new Text();
- text3.Text = "c";
- sharedStringItem3.Append(text3);
- SharedStringItem sharedStringItem4 = new SharedStringItem();
- Text text4 = new Text();
- text4.Text = "Mar";
- sharedStringItem4.Append(text4);
- SharedStringItem sharedStringItem5 = new SharedStringItem();
- Text text5 = new Text();
- text5.Text = "Terra";
- sharedStringItem5.Append(text5);
- SharedStringItem sharedStringItem6 = new SharedStringItem();
- Text text6 = new Text();
- text6.Text = "Agua";
- sharedStringItem6.Append(text6);
- SharedStringItem sharedStringItem7 = new SharedStringItem();
- Text text7 = new Text();
- text7.Text = "les";
- sharedStringItem7.Append(text7);
- SharedStringItem sharedStringItem8 = new SharedStringItem();
- Text text8 = new Text();
- text8.Text = "tic";
- sharedStringItem8.Append(text8);
- SharedStringItem sharedStringItem9 = new SharedStringItem();
- Text text9 = new Text();
- text9.Text = "rjc";
- sharedStringItem9.Append(text9);
- sharedStringTable1.Append(sharedStringItem1);
- sharedStringTable1.Append(sharedStringItem2);
- sharedStringTable1.Append(sharedStringItem3);
- sharedStringTable1.Append(sharedStringItem4);
- sharedStringTable1.Append(sharedStringItem5);
- sharedStringTable1.Append(sharedStringItem6);
- sharedStringTable1.Append(sharedStringItem7);
- sharedStringTable1.Append(sharedStringItem8);
- sharedStringTable1.Append(sharedStringItem9);
- sharedStringTablePart1.SharedStringTable = sharedStringTable1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement