Gurtz
Gurtz

Reputation: 303

Default style for a sheet in Apache POI

I am trying to work out how to specify a default CellStyle for a Sheet using POI with XSSF files.

I understand that if I call getCellStyle(0) on a Workbook, I get back the default style for the Workbook, and can make modifications as desired. I can also call setDefaultColumnStyle(index, style) on a Sheet, which will allow me to set the default style for new cells created in a particular column. But short of iterating through all columns and calling this method on each one (which would be terribly wasteful), I can't see there being any way of setting a default style for all cells of a particular sheet. (Setting it on a column-by-column basis is fine if one knows in advance what columns a user may choose to populate, but it's not ideal if a user could edit any cell in the Workbook, and a default should still apply.)

Am I missing something? Is there any way to set the default CellStyle for a specific Sheet? Thanks.

Upvotes: 1

Views: 2794

Answers (1)

Mohit
Mohit

Reputation: 134

  • use pre-defined excel template with default cell style for the sheet.
  • customize your sheet (other formatting, business logic which is user specific) in your java code.

Upvotes: 0

Related Questions