tags:

views:

181

answers:

1

Hi,

I have created a .xlsx using openxml. I am not able to open this file in office 2003.. I have also tried using compatibility pack but still the file does not open. What can be done if i need to generate .xlsx that can be opened in office 2003 as well.

Code i am using to generate .xlsx is :

public static void HelloWorldXlsx(string docName)
{
    SpreadsheetDocument package = SpreadsheetDocument.Create(docName, SpreadsheetDocumentType.Workbook);
    package.AddWorkbookPart();
    package.WorkbookPart.Workbook = new Workbook();
    WorksheetPart wspart = package.WorkbookPart.AddNewPart<WorksheetPart>();

    Cell cell = new Cell();
    cell.DataType = CellValues.InlineString;
    cell.InlineString = new InlineString(new DocumentFormat.OpenXml.Spreadsheet.Text("Hello World!")); 

    wspart.Worksheet = new Worksheet(new SheetData(new Row(cell)));

    wspart.Worksheet.Save();
    package.WorkbookPart.Workbook.AppendChild(new Sheets());
    Sheet sheet = new Sheet();

    sheet.Id = package.WorkbookPart.GetIdOfPart(wspart);
    sheet.SheetId = 1;
    sheet.Name = "Hello !";
    package.WorkbookPart.Workbook.GetFirstChild<Sheets>().AppendChild<Sheet>(sheet);
    package.WorkbookPart.Workbook.Save();
    package.Close();
}
A: 

Thanks for suggestion. I got the answer to my question .. I had not set cellReference property of Cell in my code.