Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that cell styles are overwritten during poi export

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to solve the problem that cell styles are overwritten when exporting poi". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to solve the problem that cell styles are overwritten when exporting poi".

The cell style is overwritten on poi export

Styling each cell during the poi operation, the problem is that the cell style is overwritten?

How to solve this problem?

Solution method

Void cloneStyleFrom (CellStyle var1), a method of CellStyle, is used here

Create a cell that does not affect usage and then set the style

Before creating a new cell to use

CreateCellStylecopy.cloneStyleFrom (oldercell.getCellStyle ()); / / Clone a style

Other styles can be set in createCellStylecopy and then set to the new cell

Poi's cellstyle trap, style overrides the problem cell.getCellStyle (). SetFont (font)

This sentence was originally intended to set the font style of this cell cell, but it actually affects the style of many cells.

The problem is that these cells in the Excel template are originally the same style, and the style changes obtained by get, of course, affect all of them.

Solution method

However, if you create a style directly, you will lose the original style in the Excel template, so a method of CellStyle is used here.

Void cloneStyleFrom (CellStyle var1)

It ensures that you can create a new CellStyle without losing the original CellStyle style.

The code for the question can be written as follows:

/ / to solve the problem of cell style coverage CellStyle cStyle = book.createCellStyle (); cStyle.cloneStyleFrom (cell.getCellStyle ()); cStyle.setWrapText (true); cStyle.setFont (font); cell.setCellStyle (cStyle); at this point, I believe you have a deeper understanding of "how to solve the problem of cell style overwriting in poi export". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report