Peter Chan
asked on
Excel file not created as expected
Hi,
Excel file is not created by these codes
Excel file is not created by these codes
string Path0="c:\\dp2\\Ex0.xlsx";
CreateSpreadsheetWorkbook3(Path0);
public static void CreateSpreadsheetWorkbook3(string filepath)
{
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.
Create(filepath, SpreadsheetDocumentType.Workbook);
WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook();
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new DocumentFormat.OpenXml.Spreadsheet.Worksheet(new SheetData());
DocumentFormat.OpenXml.Spreadsheet.Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.
AppendChild<DocumentFormat.OpenXml.Spreadsheet.Sheets>(new DocumentFormat.OpenXml.Spreadsheet.Sheets());
Sheet sheet = new Sheet()
{
Id = spreadsheetDocument.WorkbookPart.
GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "mySheet"
};
sheets.Append(sheet);
workbookpart.Workbook.Save();
spreadsheetDocument.Close();
}
Why?
ASKER
Sorry Ryan, file is created below
https://1drv.ms/x/s!Ai8CrEskdewXkyzD2kN7kufIeEvL
but I get this error
to open it.
https://1drv.ms/x/s!Ai8CrEskdewXkyzD2kN7kufIeEvL
but I get this error
to open it.
As I said earlier - please tell us any error message you have.
What happens if you try 'yes' to the recover option?
What happens if you try 'yes' to the recover option?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Andy,
There is no error got with the codes.
Ryan,
How to resolve the problematic message, when opening the file shown in ahove?
There is no error got with the codes.
Ryan,
How to resolve the problematic message, when opening the file shown in ahove?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If there is no error message then you code is either working correctly or just not being run at all.