Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. // Here is the text I want to add.
  2. string text = "Non-numeric text.";
  3.  
  4. // Find the SharedStringTable element and append my text to it.
  5. var sharedStringTable = document.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First().SharedStringTable;
  6. var item = sharedStringTable.AppendChild(new SharedStringItem(new Text(text)));
  7.  
  8. // Set the data type of the cell to SharedString.
  9. cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
  10.  
  11. // Set the value of the cell to the index of the SharedStringItem.
  12. cell.CellValue = new CellValue(item.ElementsBefore().Count().ToString());
  13.  
  14. string alpha = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";
  15. for (int colInx = 0; colInx < reader.FieldCount; colInx++)
  16. {
  17. AppendTextCell(alpha[colInx] + "1", reader.GetName(colInx), headerRow);
  18. }
  19.  
  20. private static void AppendTextCell(string cellReference, string cellStringValue, Row excelRow)
  21. {
  22. // Add a new Excel Cell to our Row
  23. Cell cell = new Cell() { CellReference = cellReference, DataType = new EnumValue<CellValues>(CellValues.String) };
  24. CellValue cellValue = new CellValue();
  25. cellValue.Text = cellStringValue.ToString();
  26. cell.Append(cellValue);
  27. excelRow.Append(cell);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement