Custom Style does not work after PutValue

Hi!

I have the following rather simple scenario, but it doesn’t work:

SCENARIO A:

Cell.PutValue(%datetimevariable%)
… unrelated stuff …
cellStyle = Cell.GetStyle()
cellStyle.Custom = “<any_format_string>”
Cell.SetStyle(cellStyle)

This works as expected and the date is displayed in excel with my custom format.

SCENARIO B:

Cell.PutValue(%datetimevariable%, True, True)
… unrelated stuff …
cellStyle = Cell.GetStyle()
cellStyle.Custom = “<any_format_string>”
Cell.SetStyle(cellStyle)

(changes highlighted in bold). This scenario doesn’t work (i.e. the custom format is not used when I open the workbook). It seems that using the third parameter of the PutValue function sets the style but in such a way that it cannot be changed to a custom format.

Before you ask: I need to have the code in this order; sometimes a cell gets a custom value and sometimes it doesn’t, but this is not known at the time where I call PutValue. Therefore I need to have the third parameter for PutValue True, even if there might be a custom format being applied later on.

Any idea what could be the problem?

Thanks in advance,
Bernd

@bernd.podhradsky,

Thanks for the details.

Could you provide us sample code (runnable) with template file(s) to show the issue, we will check it soon.

By the way, could you try using SetCustom() method instead of Custom attribute of Style if it makes any difference.

Hi!

SetCustom doesn’t work either. There is no template or anything. Simply a new workbook and then the few lines of code which I posted above. Do you still need an example app for this or can you create one on your own?

Thanks for your fast reply (even on a weekend - superb)!
Bernd

@bernd.podhradsky,

We need a working sample to evaluate your issue precisely to consequently figure it out soon.

Will be uploaded in a few minutes.

Hi Amjad!

When converting my production code in preparation for your example I found the mistake that I made (which was simply accessing the wrong cell index). Everything works as expected and advertised in the documentation.

Sorry for my mistake, the case can be deleted/closed :).

And thank you very much for taking your time on a weekend to support me.

Bernd

@bernd.podhradsky,

Thank you for the feedback and please feel free to contact us if you have any other queries or issues.