2

I have a query is that, I have generated an excel sheet containing many columns with Data. Now there is a column named abc_ID and the value coming from back-end is of long type as shown below

//shown below how the value is passed for that column
private Long abc_Id;
abcdeed.abc_Id(13243534540L);

HSSFCellStyle[] cellStyles = new HSSFCellStyle[11];
    HSSFCellStyle styleHeader = null;
    HSSFCellStyle styleHeaderRBorder = null;
    HSSFCellStyle cellStyleReportName = null;
    HSSFCellStyle cellStyle00 = null;
    HSSFCellStyle style_WhiteBg = null;

and I have set the following cell style of abc_ID column

if(columnHeaders[i].equals("abc_Id") && abcdeed.getabc_Id() != null){
                    cell.setCellValue(abcdeed.getabc_Id());
                    cell.setCellStyle(cellStyles[9]);

Now the issue is that finally when the excel sheet is generated and when I open that excel sheet first the value of column abc_Id looks compressed and the value in it initially is exponent type and it is because the column is of compressed type I want the column width should be expanded one and the value should not be of exponent type , I have tried to increase the cellStyles but it does not work. Please suggest the solution.

Sankumarsingh
  • 9,889
  • 11
  • 50
  • 74

2 Answers2

1

Use CELL_TYPE_STRING in all the rows for that particular Cell.

 rows.getCell(abc_Id_Cell_No).setCellType(Cell.CELL_TYPE_STRING);

and at the end

 Sheet.autoSizeColumn(abc_Id_Cell_No);

This will change all the cell values to String and autoSizeColumn will resize that column width.

Sankumarsingh
  • 9,889
  • 11
  • 50
  • 74
0

The reason your cell is showing an exponent is nothing to do with your cell width it is to do with the type of value you are putting in it.

If your number was input as a string then the cell might hide the entire value from view but the full value would still exist in the cell.

Because your value is a number you need to edit the number format parameter for your cell so that it shows the number of digits you wish to display after the decimal point. You can check the valid number format codes as a reference.

travega
  • 8,284
  • 16
  • 63
  • 91
  • but when I increase the width of the cell by mouse in the sheet the value get adjusted in numbers –  Jul 03 '13 at 04:55
  • Yes so if you don't want the default action to happen then you need to override it. As I mention your 2 options are: use a string data cell and resize the way you have been or format the layout of your number using and excel format string. – travega Jul 03 '13 at 20:27