private byte[] GerarPlanilha() { var fileArray = new MemoryStream(); using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(fileArray, SpreadsheetDocumentType.Workbook)) { WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart(); workbookpart.Workbook = new Workbook(); Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild <Sheets>(new Sheets()); for (int i = 0; i < Abas.Length; i++) { var sheet = Aba.GerarPlanilha(spreadsheetDocument, workbookpart, Abas[i]); sheets.Append(sheet); } workbookpart.Workbook.Save(); spreadsheetDocument.Close(); } return(fileArray.ToArray()); }
public static Sheet GerarPlanilha(SpreadsheetDocument spreadsheetDocument, WorkbookPart workbookpart, Aba aba) { WorksheetPart worksheetPart = workbookpart.AddNewPart <WorksheetPart>(); SheetData sheetData = new SheetData(); worksheetPart.Worksheet = new Worksheet(sheetData); var tot = spreadsheetDocument.WorkbookPart.Workbook.Sheets.Count(); Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = (uint)(tot + 1), Name = aba.Nome }; foreach (var elemento in aba.Dados) { var linha = elemento.Key; Row row = new Row() { RowIndex = (uint)linha }; var coluna = 1; foreach (var celula in elemento.Value) { object conteudo = celula.Conteudo; var cell = Celula.GerarCelula(linha, coluna, conteudo); row.AppendChild(cell); coluna++; } sheetData.AppendChild(row); } return(sheet); }
public Planilha(Aba aba) { Abas = new Aba[] { aba }; }