excelize icon indicating copy to clipboard operation
excelize copied to clipboard

Formatting dates format with (*excelize.Rows).Columns

Open maks56893 opened this issue 1 year ago • 6 comments

Hello, i have different date format in sheet. It's possible to format dates to one format when i iterating with rows and get rows values with (*excelize.Rows).Columns or i should check every cell for date type and rewrite style for date type cells?

maks56893 avatar Nov 15 '23 12:11 maks56893

You can create a style with date format by the NewStyle function at first, you will get a style index, then set the cell's style with style ID by the SetRowStyle function to change the all cell's styles in a row.

xuri avatar Nov 16 '23 07:11 xuri

It wiil override all cells in row with number type. In addition to dates, I also have regular numbers in row. This method doesn't fit

maks56893 avatar Nov 16 '23 10:11 maks56893

If the types of cells in a row are not all date, you need to set the style of the specified cells one by one with the SetCellStyle function, but you can make these cells use the same style index.

xuri avatar Nov 17 '23 02:11 xuri

Okay. To set style only for date types cells, i need to check every cell for it's type with GetCellType and then i can use SetCellStyle. But with this case it's consumes a lot of ram (+2gb for 300k rows file and 15 columns). Probably this relates with new reader for every call of GetCellType and SetCellStyle.

maks56893 avatar Nov 20 '23 09:11 maks56893

So, what I can do with it?

maks56893 avatar Dec 06 '23 07:12 maks56893

Currently, please set the date type cell style one by one with the SetCellStyle function. I will consider to improve performance for this.

xuri avatar Dec 06 '23 08:12 xuri