0

Hi All,

I cannot export big numbers to excel. I am using POI jar files for jsp to excel export. Here i am pasting my source code.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Export to Excel</title>
    </head>
    <body>
       <table cellpadding="3" cellspacing="3" border="1">
            <tr>
                <th>9 Digits</th>
                <th>18 Digits</th>
                <th>27 Digits</th>
            </tr>
                <tr>
                    <td>123456789</td>
                    <td>123456789123456789</td>
                    <td>123456789123456789123456789</td>
                </tr>
        </table>        
        <a href="exportData.jsp" >Export to Excel</a>
    </body>
</html>

exportData.jsp

<%@page contentType="application/vnd.ms-excel" pageEncoding="UTF-8"%> 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <table cellpadding="3" cellspacing="3" border="1">
            <tr>
                <th>9 Digits</th>
                <th>18 Digits</th>
                <th>27 Digits</th>
            </tr>
                <tr>
                    <td>123456789</td>
                    <td>123456789123456789</td>
                    <td>123456789123456789123456789</td>
                </tr>
        </table>
    </body>
</html>

Output
9 Digits 18 Digits 27 Digits
123456789 1.23457E+15 1.23457E+26

Kindly help me to resolve this issue

--
Vinith

3
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by vinithktp
0

This is how very large numbers are by default displayed in an excel file. Try pasting the same number (123456789123456789123456789) in a fresh excel worksheet and the result should probably be the same. You need to set the column/cell type of that excel sheet to "Text" instead of "General" which is selected by default. Look into the API of your excel exporting library for setting the same. In excel, this can be done by right clicking the cell/column -> selecting format cells -> Text.

Edited by ~s.o.s~: n/a

0

Hi all,

Thanks a lot for your help.

I have resolved the issue, i just converted number to string.

<%@page contentType="application/vnd.ms-excel" pageEncoding="UTF-8"%> 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
<%
    String bigNum = "'123456789123456789123456789'";
    String rps = "&nbsp;";
    String ss1= bigNum.replaceAll("'",rps);
%>
        <table cellpadding="3" cellspacing="3" border="1">
            <tr>
                <th>9 Digits</th>
                <th>18 Digits</th>
                <th>27 Digits</th>
                <th>Corrected</th>
            </tr>
                <tr>
                    <td>123456789</td>
                    <td>123456789123456789</td>
                    <td>123456789123456789123456789</td>
                    <td><%out.println(ss1);%></td>
                </tr>
        </table>
    </body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.