In my previous blog, "Poi and JXL write Excel performance Comparison", listed POI and JXL two ways to write Excel cells.
In general, in order to make the export better, set the cell to set the automatic column width according to the content, in the POI, using the Method Sheet.autosizecolumn ((short) i), can achieve the effect of the column width adaptive, where I is the columns index.
In JXL, column widths are generally set in the following ways
Cellview CV = new Cellview ();
Cv.setautosize (TRUE);//Auto width
cv.setsize (18);//min. width
sheet.setcolumnview (I,CV);
However, the above method cannot achieve the effect of automatic column width in the case of Chinese characters.
The effect of automatic column widths is well achieved in the following ways. Where data is the text content to be written, +4 is to adjust the effect.
if (Strutil.isnotblank (data) && (Data.getbytes (). length+4) >sheet.getcolumnwidth (i-bempty))
Sheet.setcolumnview (I,data.getbytes (). length+4); A Chinese account of 2 bytes, after debugging +4, the effect is more ideal