1
我找到的文檔沒有解決這個問題。我認爲調用cell.setCellStyle(a)和cell.setCellStyle(b)會完全覆蓋樣式a,而應用樣式b。但是,它似乎是在應用這兩者,因爲樣式不衝突。這是預期的行爲還是魔法?將setCellStyle多次應用於org.apache.poi.ss.usermodel.Cell會有什麼影響?
我找到的文檔沒有解決這個問題。我認爲調用cell.setCellStyle(a)和cell.setCellStyle(b)會完全覆蓋樣式a,而應用樣式b。但是,它似乎是在應用這兩者,因爲樣式不衝突。這是預期的行爲還是魔法?將setCellStyle多次應用於org.apache.poi.ss.usermodel.Cell會有什麼影響?
嗯,這裏的源代碼setCellStyle()
:
public void setCellStyle(CellStyle style) {
if(style == null) {
if(_cell.isSetS()) _cell.unsetS();
} else {
XSSFCellStyle xStyle = (XSSFCellStyle)style;
xStyle.verifyBelongsToStylesSource(_stylesSource);
long idx = _stylesSource.putStyle(xStyle);
_cell.setS(idx);
}
}
_cell
是org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell
型的,我無法在網上找到的源代碼。但是,由於_cell.setS(idx)
的調用僅傳入索引,因此API看起來不夠豐富,無法支持樣式合併。我強烈懷疑你的第二種風格具有你所看到的所有屬性。