Hi
I am creating an excel, where i want to make some text bold in one of the columns for which i tried with below code and its not working.
Can some one suggest me where am i doing wrong.
Regards
Sampath.
What I have tried:
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(m_SchemaFileName, SpreadsheetDocumentType.Workbook);
WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
SheetData sheetData = new SheetData();
worksheetPart.Worksheet = new Worksheet(sheetData);
Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.
AppendChild<Sheets>(new Sheets());
Sheet sheet = new Sheet()
{
Id = spreadsheetDocument.WorkbookPart.
GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "ClassMap"
};
Row row4 = new Row() { RowIndex = 4 };
Cell header4 = new Cell() { CellReference = "B4", CellValue = new CellValue("ClassIdentifyingLabel"), DataType = CellValues.String };
AddBold(spreadsheetDocument, header4);
row4.Append(header4);
public CellFormats AddCellFormat(CellFormats cf, Fonts fs)
{
cf = new CellFormats();
CellFormat cellFormat2 = new CellFormat() { NumberFormatId = 1, FontId = (UInt32)(fs.Elements<Font>().Count() - 1), FillId = 0, BorderId = 0, FormatId = 0, ApplyFill = true };
cf.Append(cellFormat2);
return cf;
}
public void AddBold(SpreadsheetDocument document, Cell c)
{
Fonts fs = AddFont(document.WorkbookPart.WorkbookStylesPart.Stylesheet.Fonts);
CellFormats cf = AddCellFormat(document.WorkbookPart.WorkbookStylesPart.Stylesheet.CellFormats,fs);
c.StyleIndex = (UInt32)(cf.Elements<CellFormat>().Count() - 1);
}