Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Here is the text I want to add.
- string text = "Non-numeric text.";
- // Find the SharedStringTable element and append my text to it.
- var sharedStringTable = document.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First().SharedStringTable;
- var item = sharedStringTable.AppendChild(new SharedStringItem(new Text(text)));
- // Set the data type of the cell to SharedString.
- cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
- // Set the value of the cell to the index of the SharedStringItem.
- cell.CellValue = new CellValue(item.ElementsBefore().Count().ToString());
- string alpha = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";
- for (int colInx = 0; colInx < reader.FieldCount; colInx++)
- {
- AppendTextCell(alpha[colInx] + "1", reader.GetName(colInx), headerRow);
- }
- private static void AppendTextCell(string cellReference, string cellStringValue, Row excelRow)
- {
- // Add a new Excel Cell to our Row
- Cell cell = new Cell() { CellReference = cellReference, DataType = new EnumValue<CellValues>(CellValues.String) };
- CellValue cellValue = new CellValue();
- cellValue.Text = cellStringValue.ToString();
- cell.Append(cellValue);
- excelRow.Append(cell);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement