I think i found a problem with DateTime Cells and Excel2007 workbook format. This problem occur only if you reWrite data on an existing worksheet. In this case the date format is lost and you have to select all datetime cells on Excel to set their format to Date and get the right date format.
Writing same data in a new worksheet doesn't lost the date format.
if the worsheet exist :
workBook.Worksheets.Remove(workBook.Worksheets[worksheetName]);worksheet = workBook.Worksheets.Add(worksheetName);
Initialize all cells from a database, the datetime format is lost
If the worksheet doesn't existworksheet = workBook.Worksheets.Add(worksheetName);
The datetime format is ok
This problem doesn't occur for Excel2003 format.
Best regards
Florent, French
Hello,
Is there anybody who can reproduce this problem. Maybe my description is not very clear as i am a French Guy...
Regards
Florent.
Hi Florent,
I'm not sure I understand exactly what you are describing. Can you post a small sample project and give me some steps I can follow in order to duplicate the problem?
Hi Mike,
Please find a sample exemple code which try to explain you which kind of problem i found.This problem occur only for 2007 Excel format, never for Excel 2003 format. Also it occur only if you export in an existing excel file.
DataTable data = new DataTable();// data is filled from a database. First column is DateTime format// first time , excel file and worksheetName doesn't existworkBook = new Workbook();worksheet = workBook.Worksheets.Add(worksheetName);foreach (DataRow datarow in data.Rows) { for (int columnIndex = 0; columnIndex < datarow.ItemArray.Length; columnIndex++) { row.Cells[columnIndex].Value = datarow[columnIndex]; } }// Save xlsx excel file// --------------------- // Export DateTime column is ok, it has the right format like dd/mm/yyyy (French culture)// ---------------------workBook.Save(xlsxFile);// Second time excel file and worksheetName existworkBook = Workbook.Load(xlsFile);
// Remove the worksheetNameworkBook.Worksheets.Remove(workBook.Worksheets[worksheetName]);
worksheet = workBook.Worksheets.Add(worksheetName);foreach (DataRow datarow in data.Rows) { for (int columnIndex = 0; columnIndex < datarow.ItemArray.Length; columnIndex++) { row.Cells[columnIndex].Value = datarow[columnIndex]; } }// Save xlsx excel file// --------------------- // Now, export DateTime column is ok but it has a wrong format like 39976// ---------------------workBook.Save(xlsxFile);
Hi,
I tested this out, but it works fine for me. A lot of the code you have here doesn't actually compile, though, so I had to modify it a bit and make some guesses.
So it could be something you are doing differently than I am. That's why I suggested you post a sample project, not just code snippets - it takes out the guesswork.
the other possibility is that I am using a newer version of the controls than you are and that this was a bug that is already fixed. Do you have the latest service release?
I tested the code you sent me and unfortunately get the same problem. In the attached file you can found 2 jpg files. One for the Excel file boutton1 click and one for boutton2 click. In the button1 file you can see the A1 cell hasn't the same format than the A2 cell....
An other strange thing, if the file created by button1 click is saved from Excel before click to the boutton2 i don't get the problem.
I use Infragistics3.Excel.v9.1 i think the latest service release, the code you sent me use V8.x. Excel and windows XP are French version.
Rgds,
I am certainly not suggesting that you use an older version. I used 8.3 as a test, because I didn't know what version you were using.
I just downloaded my sample and updated it to v9.1 and it still seems to work fine for me.
It seems to me that there are two possibilities here.
1) This is a bug in the version you are using which is fixed in the version I am using. If that's the case, then it looks like you just need to wait for the next service release.
2) There is something different in your testing than in mine. Since we are both running the same sample project, the difference must be something on the machine. The only difference seems to be that you are running French Windows XP. I don't have a French Windows XP machine to test on, unfortunately. Do you have an English XP machine you could try it on?
In your project it seems you use the V8.3 , im my project i use the V9.1 (9.1.20091.2012) , so I am surprised that you suggest I use a version older than your
Maybe i don't understand something.
The fact that it works fine for me and not you means I must be using a newer version than you.
So either you do not have the latest service release or else the internal build of the controls I am using has a fix that has not yet been released publicly. In the latter case, you will just need to wait for the next service release.