public void WriteCellFormatted(string column, int row, string value, SpreadsheetStyle style = null, int colSpan = 0) { WriteCell(column, row, value, style); if (colSpan > 0) { var endCell = SpreadsheetReader.GetColumnName(column, colSpan - 1) + row; _writer.MergeCells(column + row, endCell); } }
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); }