Hi Maciej,
The formats in DotNet are not always the same as the formats in Excel. They use a different set of format strings. So the grid can't automatically use the same formats when exporting to excel.
In order to handle this, the UltraGridExcelExporter has an event called InitializeColumn where you can get the format applied to the grid column and set the format to be applied to the Excel cells. Very often they are the same so you can just assign one to the other. But sometimes you might need to translate from a DotNet format into one Excel can handle.
Mike, I'm using NetAdvantage 2011.2 and I've differents Cell types (checkbox,textbox) in my ultragrid, and one of those have a mask as this:
I want to put the same value in excel but can't use InitializeColumn event due to the different cell types. Do you have an idea to solve this issue?
Hi,
What you could do in a case like this is use the CellExported event. This event fires after the data has been written into the cell in the Excel Worksheet. The event args give you the grid row and column, so you can get the grid cell, and also the excel worksheet, row, and column index, so you can get the Excel cell. Once you have the cell, you can set the format on that cell to whatever you want.
Thanks for your quick response. And sorry for my bad english.
I don't know if I'm doing well, but I've tried something like this:
int excelrow = e.CurrentRowIndex;
int excelcol = e.CurrentColumnIndex;
e.CurrentWorksheet.Rows[excelrow].Cells[excelcol].CellFormat = MyMask;
Which is the proper way to set the format in the cell?
Hi Marcelo,
I'm afraid I still don't understand. The thread you are posting on here is about exporting the WinGrid to Excel. Are you doing that? It sounds like maybe you are just writing an Excel Worksheet directly and apply a format to certain cells.
There is no reason I can think of why you should have to double-click anything to get the formatting to appear. Or... are you saying that you are opening up the Excel sheet and applying the formatting manually in Excel instead of in code?
For some cells my CellFormat is "hh:mm-hh:mm-hh:mm-hh:mm" so after export should look like this 00:00-00:00-00:00-00:00. But I've to double clic on the cell(edit mode) to apply the format(it's applied after leave the cell). If I don't, only looks this way 0000000000000000.
I hope you understand what I mean.
I'm afraid I don't understand what you mean. What cell are you double-clicking on? Why do you have to double-click on anything?
Has been a while, but, I've another problem, the FormatString Property worked, but I've to double clic in each cell to apply the format. The problem it's only on Excel, in LibreOffice works fine.
Isn't a method like ApplyFormat?
Thanks
I realized after, here is my code:
private void ExportExcel_CellExported(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.CellExportedEventArgs e) { if (e.GridColumn.Index > 6) { if (Convert.ToInt32(e.GridRow.Cells["IdTipoDato"].Value) == 4) { int excelrow = e.CurrentRowIndex; int excelcol = e.CurrentColumnIndex; e.CurrentWorksheet.Rows[excelrow].Cells[excelcol].CellFormat.FormatString = "hh:mm \"-\" hh:mm \"-\" hh:mm \"-\"hh:mm"; } } }
It worked, my custom format apears in excel as I want but is not working yet.
Anyway thanks a lot, now it's an excel trouble.