This project is read-only.

Writing to a cell while preserving the cell style

Oct 30, 2009 at 5:17 PM

I am trying to push information to a excel file while preserving the cell format. That is there is already a style in the cell before I push data to it and I want it to have the same style after I push data to it.  The following code is part of one of my classes. I don’t know if I am making a mistake or if there is a bug in the simple OOXML library. Any response would be greatly appreciated.

private SpreadsheetDocument spreadsheetDocument;

public void WriteToCellWith(string worksheetName, string columnName, uint rowNumber, object cellValue)

{

WorksheetPart worksheetPart = SpreadsheetReader.GetWorksheetPartByName(spreadsheetDocument, worksheetName);

SpreadsheetStyle spreadsheetStyle = WorksheetReader.GetStyle(spreadsheetDocument, worksheetPart, columnName, rowNumber);

WorksheetWriter.PasteText(spreadsheetDocument, worksheetPart, columnName, rowNumber, cellValue.ToString());

WorksheetWriter.SetStyle(spreadsheetStyle, spreadsheetDocument, worksheetPart, columnName, rowNumber);

}

Oct 30, 2009 at 7:39 PM

Let me elaborate a little bit. The WorksheetReader.GetStyle function always returns null for its FormatCode. So I can never perserve the format code.