I want to disable GridLines in excel and put custom borders to excel cells using open xml in C#
I have tried with below code but is throwing exception when i open the excell,
the exception is "Repaired Part: /xl/worksheets/sheet.xml part with XML error. Load error. Line 1, column 0."
using (SpreadsheetDocument xl = SpreadsheetDocument.Create(sFile, SpreadsheetDocumentType.Workbook))
{
WorkbookPart wbp = xl.AddWorkbookPart();
WorksheetPart wsp = wbp.AddNewPart<WorksheetPart>();
Workbook wb = new Workbook();
FileVersion fv = new FileVersion();
fv.ApplicationName = "Microsoft Office Excel";
Worksheet ws = new Worksheet();
SheetViews sheetViews = new SheetViews();
SheetView sheetView = new SheetView();
sheetView.ShowGridLines = new BooleanValue(false);
sheetViews.Append(sheetView);
ws.Append(sheetViews);
WorkbookStylesPart wbsp = wbp.AddNewPart<WorkbookStylesPart>();
//// add styles to sheet
wbsp.Stylesheet = CreateStylesheet();
wbsp.Stylesheet.Save();
//// add styles to sheet
////wbsp.Stylesheet = GenerateStyleSheet();
//wbsp.Stylesheet.Save();
Columns columns = new Columns();
columns.Append(CreateColumnData(1, 1, 25));
ws.Append(columns);
//// generate rows
SheetData sd = CreateSheetData(products);
ws.Append(sd);
wsp.Worksheet = ws;
wsp.Worksheet.Save();
MERGEiNITIALcELLS(wsp);
wb.Append(fv);
CreateSheet(wbp, wsp, wb);
xl.WorkbookPart.Workbook = wb;
xl.WorkbookPart.Workbook.Save();
xl.Close();
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…