Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8803453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:20:41+00:00 2026-06-14T01:20:41+00:00

When I create excel sheet through java ,the column which has number datatype in

  • 0

When I create excel sheet through java ,the column which has number datatype in the oracle table, get converted to text format in excel.I want it to remain in the number format.Below is my code snippet for excel creation.

    public boolean prepareExcelFilefromQuery(String chanType,
                    Collection<List> queryDataRowWise, HttpServletResponse response)

            {
                List<String> queryDataColWise;
                HSSFRow row = null;
                HSSFCell cell = null;
                Integer rowCounter = 0;
                Integer colCounter;
                boolean success = false;
                try {

                    Iterator<List> rowIterator = queryDataRowWise.iterator();
                    HSSFWorkbook workbook = new HSSFWorkbook();
                    HSSFSheet sheet = workbook.createSheet(chanType + " Report");
                    System.out.println("First row/..." + sheet.getFirstRowNum());
                    while (rowIterator.hasNext()) {
                        colCounter = 0;

                        queryDataColWise = (List) rowIterator.next();
                        Iterator colIterator = queryDataColWise.iterator();

                        row = sheet.createRow(rowCounter++);
                        while (colIterator.hasNext()) {
                            cell = row.createCell(colCounter++);
                            Object o = colIterator.next();

                            if (o instanceof java.lang.String) {
                                String s = (String) o;
                                cell.setCellValue(s);
                            } else if (o instanceof java.lang.Double) {
                                Double d = (Double) o;
                                cell.setCellValue(d);
                            } else if (o instanceof java.lang.Integer) {
                                Integer i = (Integer) o;
                                 cell.setCellType(cell.CELL_TYPE_NUMERIC);
                                cell.setCellValue(i);
                            } else if (o instanceof java.util.Date) {
                                Date date = (Date) o;

                                SimpleDateFormat FORMATTER;

                                FORMATTER = new SimpleDateFormat("MM/dd/yyyy");
                                String date11 = FORMATTER.format(date);
                                HSSFCellStyle cellStyle = workbook.createCellStyle();
                                cellStyle.setDataFormat(HSSFDataFormat
                                        .getBuiltinFormat("m/d/yy"));
                                cell.setCellStyle(cellStyle);
                                cell.setCellValue(FORMATTER.parse(date11));
                            }
                        }
                    }

                    workbook.write(response.getOutputStream());
                    success = true;

                } catch (Exception e) {
                    logger.debug(
                            "Exception caught in prepareExcelFilefromQuery class ", e);
                    System.out
                            .println("Exception caught in prepareExcelFilefromQuery class ");
                    e.printStackTrace();

                } 
                }
                return success;
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:20:42+00:00Added an answer on June 14, 2026 at 1:20 am

    It just use format like 0. More Format

    CellStyle numberStyle = wb.createCellStyle();
    numberStyle.setDataFormat(format.getFormat("0"));
    
    CellStyle dateStyle = wb.createCellStyle();
    dateStyle.setDataFormat(format.getFormat("d-mmm-yy"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create excel sheet from my Java code which contains charts like
I need to create an excel sheet with a field status. It is a
I have a Excel sheet with two columns and I need to create new
I have the this code that will create excel file and work sheet then
I have created Excel Sheet using Java program. It works fine. My problem is,
I am using POI 3.8 to create Excel sheets using Java I have created
Possible Duplicate: Create Excel file in Java How to save output in excel format
I'm currently considering a number of options for copying an excel sheet into a
I am using following POI api to write on excel through java code public
I am trying to create an excel sheet in a code-behind and then download

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.