Generate excel sheet list file through program

Hi,
I have to generate list in excel which is having column with fixed length.
I m using classical report for output then in output i m generating excel file .
but that file is not with fixed column length.
how ALV will be useful in this case
Please help.
Regards,
Sudhir Ghag.

Hi,
As from Ur query u required the output in the fixed length of columns as output in the excel. This is not possible by using Type pool ole2. We have to control the length of the excel cell as fixed.
Hope this will help U

Similar Messages

  • Generating EXCEL sheet from an iView

    hiii......
    i've developed a iView which holds list of users in a dropdown list box....and a button...
    now i want this data to be filled in a excel sheet when i click this button.....
    can some one send me sample code for this task...
    i have some code which doesnt work.......
    i cudnt debug this.....
    plz go through.......
    import java.io.FileOutputStream;
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFCellStyle;
    import org.apache.poi.hssf.usermodel.HSSFDataFormat;
    import org.apache.poi.hssf.usermodel.HSSFFont;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    public class XLSGen {
    public void generate() throws Exception {
         HSSFWorkbook wb = new HSSFWorkbook();
         FileOutputStream fileOut = new FileOutputStream("workbook.xls");
         HSSFSheet sheet = wb.createSheet();
         HSSFRow row = sheet.createRow(3);
         HSSFCell cell = row.createCell((short)0);
         HSSFCellStyle cs1 = wb.createCellStyle();
         HSSFCellStyle cs2 = wb.createCellStyle();
         HSSFCellStyle cs3 = wb.createCellStyle();
         HSSFDataFormat df = wb.createDataFormat();
         HSSFFont f = wb.createFont();
         HSSFFont f2 = wb.createFont();
         f.setFontHeightInPoints((short) 12);
         f2.setFontHeightInPoints((short) 10);
         cs1.setFont(f);
         cs1.setDataFormat(df.getFormat("#,##0.0"));
         cs2.setFont(f2);
         cell.setCellValue(1);
         row.createCell((short)1).setCellValue(1.2);
         row.createCell((short)2).setCellValue("This is a string");
         row.createCell((short)3).setCellValue(true);
    //     HttpServletResponse res = request.getServletResponse(true);
    //     res.setContentType("application/vnd.ms-excel");
    //     wb.write(res.getOutputStream());
         wb.write(fileOut);
         fileOut.close();
    thanks and regards,
    Sudheer

    Hi ,
    Modified your code .
    public void generate(IPortalComponentRequest request) throws Exception {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    HSSFRow row = sheet.createRow(3);
    HSSFCell cell = row.createCell((short)0);
    HSSFCellStyle cs1 = wb.createCellStyle();
    HSSFCellStyle cs2 = wb.createCellStyle();
    HSSFCellStyle cs3 = wb.createCellStyle();
    HSSFDataFormat df = wb.createDataFormat();
    HSSFFont f = wb.createFont();
    HSSFFont f2 = wb.createFont();
    f.setFontHeightInPoints((short) 12);
    f2.setFontHeightInPoints((short) 10);
    cs1.setFont(f);
    cs1.setDataFormat(df.getFormat("#,##0.0"));
    cs2.setFont(f2);
    cell.setCellValue(1);
    row.createCell((short)1).setCellValue(1.2);
    row.createCell((short)2).setCellValue("This is a string");
    row.createCell((short)3).setCellValue(true);
    HttpServletResponse res = request.getServletResponse(true);
    try {
    res.setContentType("application/vnd.ms-excel");
    wb.write(res.getOutputStream());
    }catch(Exception e) {}
    Check this blog for more
    Create an excel file from JAVA using HSSF api

  • Error while opening the EXCEL Sheet from a Report Program

    Hi All,
    I am getting an error saying 'SYLK: File Format is not valid' when my program is trying to open an excel sheet. I am using the function module WS_EXCEL to download it to excel sheet.
    Following is the code:
    Excel download
    types: begin of t_excel,
             c01(20),
             c02(20),
             c03(20),
             c04(20),
             c05(70),
             c06(20),
             c07(20),
             c08(20),
             c09(20),
             c10(20),
           end of t_excel.
    data: a00_excel type standard table of t_excel.
    concatenate 'C:\' sy-repid sy-uzeit 'FILE01' '.xls' into z_fname.
    condense z_fname no-gaps.
    call function 'WS_EXCEL'
          exporting
               filename = z_fname
          tables
               data     = a00_excel
          exceptions
               others   = 1.
    if sy-subrc ne 0.
       message e019(zsd).
      Download to Excel failed.
    endif.
    a00_excel contains the data that is to be downloaded into the excel sheet. I used the same code in the other program it is working fine. If you see in the type declaration for C5 its 70 characters, i tried putting it as same as others to 20... still it doesnt work.
    Thank You,
    Suresh

    Not sure man,  your code works ok for me.
    report zrich_0001.
    types: begin of t_excel,
    c01(20),
    c02(20),
    c03(20),
    c04(20),
    c05(70),
    c06(20),
    c07(20),
    c08(20),
    c09(20),
    c10(20),
    end of t_excel.
    data: a00_excel type standard table of t_excel.
    data: x00_excel like line of a00_excel.
    data: z_fname type string.
    x00_excel-c01 = 'A'.
    x00_excel-c02 = 'B'.
    x00_excel-c03 = 'C'.
    x00_excel-c04 = 'D'.
    x00_excel-c05 = 'E'.
    x00_excel-c06 = 'F'.
    x00_excel-c07 = 'G'.
    x00_excel-c08 = 'H'.
    x00_excel-c09 = 'I'.
    x00_excel-c10 = 'J'.
    append x00_excel to a00_excel.
    x00_excel-c01 = 'K'.
    x00_excel-c02 = 'L'.
    x00_excel-c03 = 'M'.
    x00_excel-c04 = 'N'.
    x00_excel-c05 = 'O'.
    x00_excel-c06 = 'P'.
    x00_excel-c07 = 'Q'.
    x00_excel-c08 = 'R'.
    x00_excel-c09 = 'S'.
    x00_excel-c10 = 'T'.
    append x00_excel to a00_excel.
    concatenate 'C:' sy-repid sy-uzeit 'FILE01' '.xls' into z_fname.
    condense z_fname no-gaps.
    call function 'WS_EXCEL'
         exporting
              filename = z_fname
         tables
              data     = a00_excel
         exceptions
              others   = 1.
    if sy-subrc ne 0.
      message e019(zsd).
    *  download to excel failed.
    endif.
    Regards,
    Rich Heilman

  • Generating Excell Sheet using Reports 9i

    Hello,
    I wanna know how can I do to generate one excell sheet using reports, without
    use the option that4s generate text file using tab. I wanna know if someone have
    example codes, or library4s.
    Thanks,
    Paulo Sergio

    Here are some notes we created from the demo below. This works great for generating true formated excel output in 9i Reports using 9ias Rel2.
    Notes from
    http://otn.oracle.com/products/reports/htdocs/getstart/demonstrations/index.html
    Output to Excel with Oracle9i Report
    1.     Create an Excel template for the report. It should contain generic information such as title, logo and column headers
    2.     Cretae a sample line of data in the spreadsheet
    3.     Save the Excel spreadsheet as a Web page. File | Save As Web Page
    4.     Open the Web page you just created in Reports Builder
    5.     Double-click on Web Source node to display the HTML code for the Excel spreadsheet
    6.     Note how Excel generated HTML and XML code for the spreadsheet you created. Reports Builder also adds its own JSP tags
    7.     Add the Data Source An SQL Query
    8.     Modify the Web Source. Now that youve written the query, you can modify the Web source to tell Reports Builder to display your report in Excel.
    9.     Click on the Web Source icon in the toolbar.
    10.     To force the browser to open MS Excel it is necessary to change the HTTP Content Type to a specific MIME Type:
    application/vnd.ms-excel
         Insert the following line immediately before the <rw:report id=report> tag
              <%@ page contentType=application/vnd.ms-excel %>
         (This is a standard JSP directive to set a MIME Type (Content Type) )
    11.     To respect Excel format, you should delete the blank lines above the <html> tag.
    12.     Now, use Oracle 9i Reports JSP tags to add the data retrieved by your SQL Query to the report.
    13.     Search for the sample line of data you added to your Excel spreadsheet
    14.     Each line is saved as an HTML Table Row tag ( <tr> ).
    15.     Each column is mapped as an HTML Table Data tag ( <td> ).
    16.     Using Reports JSP Tags, add a Reports repeating frame tag to loop around the Data Model group.
    17.     To help, show the Object navigator next to the Web Source Window. All group information is now visible in the Object Navigator
    18.     Enclose the sample line of code in the Web source with the Reports9i JSP repeating tag.
    Use from menu Insert | Repeating Frame at beginning of sample
    Move the closing repeating tag after the </tr> tag.
    Start of the repeating tag would be
    <rw:foreach id=foreach src=>
    Ending of the repeating frame would be
    </rw:foreach>
    19.     In the opening of the repeating tag (<for each>), add the name of the group the tags enclose. JSP custom tags require a unique identifier.
    For example: <rw:foreach id=gEmpNoId src=G_EMPNO>
    20.     Now, map the cells of the Excel spreadsheet to the corresponding field from your data model.
    Select on the data value. From menu select Insert | Field. The source of the tag is the name of the field in the query.
    21.     Repeat the operation for each field of the report. Note: do not forget to specify a unique identifier for each field.
    22.     The code now contains a repeating frame. You have also mapped each cell in the Excel spreadsheet to the corresponding field in the data model
    23.     Save the report as a Reports JSP. You can test the report using the Run Web Layout icon in the toolbar
    24.     The execution of a Web Layout report from Reports Builder creates a temporary HTML file and launches the browser. The browser does not launch Excel because the document is saved as an HTML file. To launch Excel from the browser you need to test it from Reports Server.
    25.     In order to have the report appear inside Excel, you need to execute it with the Reports Server under OC4J. To do this you need to:
    First, start an OC4J instance from Oracle 9iDS see How to Execute Reports Services from Oracle 9iDS on OTN. Then, copy the JSP to a directory. For example: $IDS_HOME/reports/j2ee/reports_ids/web/test
    26.     Enter the URL to execute the jsp. The JSP is executed from an OC4J instance.
    http://reports9iTestServer:8888/reports/test/ListOfEmployees.jsp?userid=scott/tiger@ora901
    27. The browser launches Microsoft Excel and displays the data from your report.

  • Excel sheet listing

    Hi!, I'm writing an application, where in I need to list all the sheets in an Excel file. I'm able to read data from a single excel sheet. I need to list all the existing sheets in an Excel file. I would like to know if there is any process using Java API to list all the availablie sheets in an Excel file.
    Thanks in advance
    Ravi.

    Hi!, I'm writing an application, where in I need to
    list all the sheets in an Excel file. I'm able to read
    data from a single excel sheet. I need to list all the
    existing sheets in an Excel file. I would like to know
    if there is any process using Java API to list all the
    availablie sheets in an Excel file.
    Thanks in advance
    Ravi.Ravi:
    I use the following code to obtain the number and names of
    sheets from an Excel file:
    Connection con = null;
    con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=d:\\weblogic\\temp\\TestExcelData.xls;DriverID=22;READONLY=true","","");
    if (con != null) {
    System.out.println(" Connection successfully made \n " + con.toString());
    DatabaseMetaData dbMetaData = null;
    dbMetaData = con.getMetaData();
    if (dbMetaData == null) {
    System.out.println(" Unable to obtain database metadata ");
    System.exit(0);
    ResultSet rsTables = dbMetaData.getTables(null, null, null, null);
    while (rsTables.next()) {
    System.out.println(" name " + rsTables.getString("TABLE_NAME"));
    System.out.println(" Tables are selectable : " +
    dbMetaData.allTablesAreSelectable());
    ResultSet rsColumns = dbMetaData.getColumns(null, null, "Sheet1%", null);
    while (rsColumns.next()) {
    System.out.println(" table " + rsColumns.getString("TABLE_NAME") +
    " column " + rsColumns.getString("COLUMN_NAME") +
    " datatype " + rsColumns.getString("DATA_TYPE"));
    String sql = "select roomrate1 from Sheet1$;";
    PreparedStatement pstmt = con.prepareStatement(sql);
    ResultSet rs = pstmt.executeQuery();
    The result from getColumns shows that a table name is Sheet1$,
    and column name is roomrate1, but trying to execute the
    select statement fails with the exception:
    java.sql.SQLException: [Microsoft][ODBC Excel Driver] Syntax error in FROM clause.
    I understand you have been able to read data from a work sheet.
    Can you tell me what I am doing wrong or share a code snippet as
    an example? Thanks.
    I under

  • Generate Excel Sheet using Servlet

    Hi all,
    I have a HTML page with some fields and a submit button. This HTML page is calling a servlet. When this servlet is called from this HTML, I want the servlet to take the values in the fields of the HTML page and create an Excel Sheet with those values.
    Thanks,
    Anirvan

    Write all the details into an jsp/html as usual...
    just change the content type of the response of the servlet before you redirect.
    res.setContentType("application/vnd.ms-excel");
    res.setHeader("Content-Disposition", "attachment; filename=\"fileName.xls\"");

  • Generating Excel Sheet from Reports ......

    Hi,
    I want to generate reports both in Oracle Reports 6.0, as well
    as in Microsoft Excel. The simplest solution I thought was to
    generate the Oracle Report first and then, give a button on the
    report, which when pressed, can scan the data in the generated
    report and write it into an Excel file. The writing part to
    Excel file, I can do by using the OLE2 automation. I am not able
    to find a way to read the data in the generated report
    programatically. Is this possible and if yes, then can anyone
    suggest me a way to do this. Is there an alternate solution to
    this problem.
    regards,
    Abhilash

    Hi ,
    Modified your code .
    public void generate(IPortalComponentRequest request) throws Exception {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    HSSFRow row = sheet.createRow(3);
    HSSFCell cell = row.createCell((short)0);
    HSSFCellStyle cs1 = wb.createCellStyle();
    HSSFCellStyle cs2 = wb.createCellStyle();
    HSSFCellStyle cs3 = wb.createCellStyle();
    HSSFDataFormat df = wb.createDataFormat();
    HSSFFont f = wb.createFont();
    HSSFFont f2 = wb.createFont();
    f.setFontHeightInPoints((short) 12);
    f2.setFontHeightInPoints((short) 10);
    cs1.setFont(f);
    cs1.setDataFormat(df.getFormat("#,##0.0"));
    cs2.setFont(f2);
    cell.setCellValue(1);
    row.createCell((short)1).setCellValue(1.2);
    row.createCell((short)2).setCellValue("This is a string");
    row.createCell((short)3).setCellValue(true);
    HttpServletResponse res = request.getServletResponse(true);
    try {
    res.setContentType("application/vnd.ms-excel");
    wb.write(res.getOutputStream());
    }catch(Exception e) {}
    Check this blog for more
    Create an excel file from JAVA using HSSF api

  • Problem in generating excel sheet o/p from ALV report

    Hi to all
    I have developed an ALV grid report which is showing o/p in screen  but
    when exporting or downloading to excel i am getting only field header and
    o/p is not shown in print preview also.
    Plz guide me...
    Regards
    Anubhav

    Hi Anubhav,
    It might be problem with some configuration or with the gui plz contact ur basis consultanat regarding this issue and get it done..
    Regards,
    Satish ...

  • Help required on deleting temporary files through program

    I could able to create, write and read from a temporary file. But I am unable to delete it. Can anyone help me to fix this. Here is the code.
    Thanks in advance.
    import java.io.*;
    public class Test {
       File file1 = new File("C:\\temp");
       public static void main(String[] args)throws Exception {
           Test t = new Test();
            t.createTempFiles();
            t.read();
            t.delete();
        public void createTempFiles(){
            try{
                File temp = File .createTempFile( "TempFileName", ".tmp", new File ( "C:\\temp" ) );
                BufferedWriter bufferWriter = new BufferedWriter(new FileWriter(temp));
                bufferWriter.write("Temporary File");
                bufferWriter.close();
             catch(Exception exp){
                exp.printStackTrace();
       public void read()throws Exception{
           File file[] = file1.listFiles();
            for(File obj: file){
            BufferedReader reader = new BufferedReader(new FileReader(obj);
            System.out.println(reader.readLine());
       public void delete(){
          File file[] = file1.listFiles();
          for(File fl : file){
             System.out.println(fl.delete());
    }

    I think you are unable to delete because you never close the reader, so the operating system reports the file is still in use.

  • Numberformat error in generating excel sheet

    i am changing the numberformat through these commands but getting error :-
    NumberFormat fivedps =fivedps=new NumberFormat("#######.##");
    WritableCellFormat fivedpsFormat = new WritableCellFormat(fivedps);
    WritableCellFormat fivedpsFontFormat = new WritableCellFormat (times16font, fivedps);
    ERRORS:-
    java.text.NumberFormat is abstract; cannot be instantiated
    NumberFormat fivedps =fivedps=new NumberFormat("#######.##");
    constructor WritableCellFormat (java.text.NumberFormat)
    location: class jxl.write.WritableCellFormat
    WritableCellFormat fivedpsFormat = new WritableCellFormat(fivedps);
    how do i solve these problems and achieve the same functioning?

    Try DecimalFormat

  • Crystal report - generate CSV file through Java interface

    Hi,
    I need to generate a Character Seperated File through Crystal Report 10 using Java.
    What constant stands for CSV Format and what value of SI_PROGID we can provide to pull the CSV format.
    Eg. SI_PROGID = ceProgID.EXCEL or SI_PROGID = ceProgID.PDF .....
    Currentlly we are crystalLibs.jar to connect the Crystal server.
    Thanks In Advance

    In BusinessObjects Enterprise installations, the following ProgIDs are valid.
    CrystalEnterprise.Analytic
    CrystalEnterprise.AppFoundation
    CrystalEnterprise.Calendar
    CrystalEnterprise.Category
    CrystalEnterprise.Connection
    CrystalEnterprise.Designer
    CrystalEnterprise.Destination
    CrystalEnterprise.DiskUnmanaged
    CrystalEnterprise.Event
    CrystalEnterprise.Excel
    CrystalEnterprise.Folder
    CrystalEnterprise.FavoritesFolder
    CrystalEnterprise.Ftp
    CrystalEnterprise.Hyperlink
    CrystalEnterprise.Inbox
    CrystalEnterprise.InfoView
    CrystalEnterprise.LicenseKey
    CrystalEnterprise.Managed
    CrystalEnterprise.MyInfoView
    CrystalEnterprise.ObjectPackage
    CrystalEnterprise.Overload
    CrystalEnterprise.Pdf
    CrystalEnterprise.PersonalCategory
    CrystalEnterprise.Powerpoint
    CrystalEnterprise.Program
    CrystalEnterprise.Report
    CrystalEnterprise.Rtf
    secEnterprise
    secLDAP
    CrystalEnterprise.Server
    CrystalEnterprise.ServerGroup
    CrystalEnterprise.Shortcut
    CrystalEnterprise.Smtp
    CrystalEnterprise.Txt
    CrystalEnterprise.Universe
    CrystalEnterprise.User
    CrystalEnterprise.UserGroup
    CrystalEnterprise.Webi
    CrystalEnterprise.Word

  • Excel sheet generation through RFC call from a BSP application

    Hi,
      I am calling a RFC FM ( in R3)  in Event handler 'OnInputProcessing' of a BSP application in a SRM server.
    That function submits a report program which geneates a excel sheet using download FM . Excel sheet is not getting generated.
    But when i am calling this RFC FM  (in R3) from a report program ( in srm server)
    this is generating an ecel sheet.
    I want to have call RFC from BSP application.
    I tried the way of submit a program ( which contains RFC call) from BSP application ,but it is also not generating excel sheet.
    My ultimate AIM is to generate excel sheet by trigerring CALL or submit from BSP
    application.
    can any one propose solution for it.
    Useful answers will be rewarded.

    Hi,
    Which FM is it. I guess that the download generated is a SAP gui oriented solution, which will never work in a web environment
    Eddy
    PS. Reward useful answers and earn points yourself

  • PI to genrate excel sheet as output

    Hello All,
    Interface is outbound. The mode of communicaiton from SAP ECC to SAP PI is through Proxy XML. And from SAP PI to Target application the mode of communication is Excel sheet. PI has to generate Excel sheet to the target system read.PI version using is 7.1
    Can you please help in getting solution for this requirement
    Thanks,
    Regards,
    Moorthy

    Hi Naresh - Did you check the below blogs?
    Convert incoming XML to Excel or Excel XML – Part 1 - XSLT Way
    Convert incoming XML to Excel Sheet Part 2 – Adapter Module way
    Excel Files - How to handle them in SAP XI/PI (The Alternatives)

  • Problem when opening excel sheet in jsp

    Hi friends
    When i try to open excel sheet from my program I am getting two problems
    1. first row of excel sheet is empty
    2. while opening I am getting error message of "the file is not in a recognizable format"
    Please help me..It is an urgent work
    my code
    <%@page language="java" import="java.io.*,java.text.*,java.sql.*,java.util.*"%>
    <%
    Class.forName("org.gjt.mm.mysql.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://256.136.119.86/mydb","zzz","zzz");
    Statement st = conn.createStatement();
    StringBuffer sb = new StringBuffer();
    sb.append("SAP#" + "\t");
    sb.append("x-plant status" + "\t");
    sb.append("Total Amount" +"\t");
    sb.append(">90 days" + "\t");
    sb.append("\n");
    try
    String query="select * from temp_Xplant";
    ResultSet rs = st.executeQuery(query);
    while(rs.next()){
    sb.append(rs.getString("sapNo") + "\t");
    sb.append(rs.getString("status")+ "\t");
    sb.append(rs.getString("amt") + "\t");
    sb.append(rs.getString("days") + "\t");
    sb.append("\n");
    conn.close();
    st.close();
    catch (Exception e)
    out.println("error");
    conn.close();
    st.close();
    response.setContentType("application/vnd.ms-excel");
    // response.setHeader("Content-Disposition", "attachment; filename=\"test.xls\"");
    String testt = "tests.xls";
    response.setHeader("Content-Disposition", "attachment; filename="+testt);
    out.println(sb.toString());
    out.close();
    %>
    thanks in advance

    The problem here is, you have setted the content type as excel sheet and you are writing some String content into the output stream. when excel tries to read the String content it will surely throw some error. Lot of excel APIs are available in the market to generate excel sheets.
    you can find one in the below URL.
    http://www.teamdev.com/downloads/jexcel/docs/JExcel-PGuide.html

  • Reg:processing of excel sheet by SAP XI

    Hi all,
    Is it possibel for XI to pick data from an excel sheet.
    If so,can anyone please let me know some useful blogs.
    Thanks in advance.

    hi,
    u can check the below blogs to process the Excel sheet and generate Excel sheet using XI
    /people/sap.user72/blog/2005/07/04/read-excel-instead-of-xml-through-fileadapter (process excel sheet)
    /people/michal.krawczyk2/blog/2005/12/10/xi-generating-excel-files-without-the-java-nor-the-conversion-agent-not-possible (Generate Excel sheet)
    Thank You,
    Madhav.
    Note: Points If useful.

Maybe you are looking for