public void WorksheetPasteTest() { MemoryStream stream = SpreadsheetReader.Create(); SpreadsheetDocument doc = SpreadsheetDocument.Open(stream, true); WorksheetPart worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1"); WorksheetWriter writer = new WorksheetWriter(doc, worksheetPart); writer.PasteNumber("D3", "2"); writer.PasteNumber("D4", "3"); writer.PasteNumber("D5", "4"); //Add total without a calc chain writer.FindCell("D6").CellFormula = new CellFormula("SUM(D3:D5)"); //Save to the memory stream, and then to a file SpreadsheetWriter.Save(doc); SpreadsheetWriter.StreamToFile(string.Format("{0}\\output.xlsx", GetOutputFolder()), stream); }
public void WorksheetCopyTest() { MemoryStream stream = SpreadsheetReader.Copy(string.Format("{0}\\Templates\\template.xlsx", Directory.GetCurrentDirectory())); SpreadsheetDocument doc = SpreadsheetDocument.Open(stream, true); WorksheetPart worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1"); WorksheetWriter writer = new WorksheetWriter(doc, worksheetPart); writer.PasteNumber("B3", "10"); writer.PasteNumber("B4", "20"); writer.PasteNumber("B5", "40"); //Add total without a calc chain writer.FindCell("B6").CellFormula = new CellFormula("SUM(B3:B5)"); //Change the print area from A1:I30 writer.SetPrintArea("Sheet1", "A1", "D10"); //Save to the memory stream, and then to a file SpreadsheetWriter.Save(doc); SpreadsheetWriter.StreamToFile(string.Format("{0}\\templatetest.xlsx", GetOutputFolder()), stream); }
public void WorksheetNumberFormatTest() { MemoryStream stream = SpreadsheetReader.Create(); SpreadsheetDocument doc = SpreadsheetDocument.Open(stream, true); WorksheetPart worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1"); SpreadsheetStyle style = SpreadsheetReader.GetDefaultStyle(doc); WorksheetWriter writer = new WorksheetWriter(doc, worksheetPart); style.FormatCode = "0.00"; writer.PasteNumber("B3", "123", style); //Save to the memory stream, and then to a file SpreadsheetWriter.Save(doc); SpreadsheetWriter.StreamToFile(string.Format("{0}\\numberformat.xlsx", GetOutputFolder()), stream); }