Re: Formatted value of a Calc date cell?

Niklas Nebel <[email protected]>
Newsgroups gmane.comp.openoffice.devel.api
Message-ID <[email protected]>
On 11/04/10 17:15, Scott Deerwester wrote:
> I'm having trouble understanding how to get the formatted value of a date
> cell. I'm using the PyUNO binding of the API, and trying to reformat a date
> cell as YYYY-MM-DD. Here's (a somewhat slimmed down version of) the relevant
> portion of the code, with various things I've tried in comments.
>
>      locale = document.getPropertyValue("CharLocale")
>      formats = document.getNumberFormats()
>      formatID = formats.queryKey("YYYY-MM-DD", locale, False)
>      line = []
>
>      for r in range(dataRange.StartRow, dataRange.EndRow):
>          for c in range(dataRange.StartColumn, dataRange.EndColumn):
>              cell = sheet.getCellByPosition(c,r)
>              cellType = cell.getType()
>
>              if cellType == UNO_VALUE and cell.NumberFormat == UNO_DATE:

If UNO_DATE is from the com.sun.star.util.NumberFormat constants, this 
condition is wrong. The "NumberFormat" property contains keys, such as 
from the queryKey call above.

Also note that queryKey works only if the format is already present for 
the locale. Otherwise it returns -1 and you have to use addNew.

Niklas
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.