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 WorksheetMergeCellsTest() { MemoryStream stream = SpreadsheetReader.Create(); SpreadsheetDocument doc = SpreadsheetDocument.Open(stream, true); WorksheetPart worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1"); WorksheetWriter writer = new WorksheetWriter(doc, worksheetPart); SpreadsheetStyle style = SpreadsheetReader.GetDefaultStyle(doc); Cell cell = writer.PasteSharedText("B2", "Merged cells"); style.IsUnderline = true; writer.SetStyle(style, "B2"); Cell cell2 = writer.FindCell("C2"); cell2.StyleIndex = cell.StyleIndex; writer.MergeCells("B2", "C2"); //Save to the memory stream, and then to a file SpreadsheetWriter.Save(doc); SpreadsheetWriter.StreamToFile(string.Format("{0}\\merge.xlsx", GetOutputFolder()), stream); }