Problem in reading from excel file with my requirement

Hi,
Below is my input excel file format
A    XXX
B    XXX
C    XXX
D    E   F   G  H  I    J  K  L  M  N
XX   XX  XX  XX.........................XX
All the A...N are headings and XX's are values.
How should I define an internal table for this requirement. I am using FM TEXT_CONVERT_XLS_TO_SAP to read input file.
Please let me know the correct way to define internal table for the above file format.
Regards,
Cheritha

Hello Cheritha,
Your final internal table(t_final) should have all the fields viz. A, B, C, D etc.
You need to read the file to an internal table say t_data. In the internal table t_data, the field values will be each row in this internal table.
So you need to loop on t_data and based on the field name assign it to the corresponding field in the internal table t_final.
Hope this is clear if any clarification please do reply
Regards
Farzan

Similar Messages

  • .exe reading from Excel files

    Hi everybody,
    I know similar questions have been asked lots of times but while searching the forum didn't find an anwer to my problem.
    I created an exe file (using exe4j) of a java application which reads form Excel files. Although it works when I run it from my editor, when running the exe file it cant find the Excel file. More specifically I have this error:
    "java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
    In order to read from excel files I use POI. I used it so as not to use ODBC driver and make it possible to run in every computer. When adding the driver, the exe works.Do you know a way to make it work without having to install the Driver?
    Thanks in Advance

    You need database drivers to read excel spread sheets?
    Also, why did you make it an exe? just jar it and be done with it.

  • Error in reading from excel file

    hi,
    I have written a program which reads from excel file
    and based on the value of the column i have to do something.
    Everything is fine but when i run it, it produces an error message
    Exception: For input string: "851.0"
    the value 851.0 is acually the value of the first column.
    Here is the code and i hope someone can help me to find the solution
    try{
                               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                               Connection con = DriverManager.getConnection( "jdbc:odbc:exceltest" );
                               Statement st = con.createStatement();
                               ResultSet rs = st.executeQuery( "Select * from [Sheet1$] " );
                               ResultSetMetaData rsmd = rs.getMetaData();
                               int numberOfColumns = rsmd.getColumnCount();
                               while (rs.next()) {
                                            for (int i = 1; i <= numberOfColumns; i++) {
                                                 if(i==1){
                                                            String columnValue1 = rs.getString(i);
                                                            custNo =Integer.parseInt(columnValue1);
                                                           // System.out.println(columnValue1);     
                                                            found=search(custNo);
                                                            if (found==false)
                                                                 insert(custNo);
                                                            System.out.println(columnValue1);     
                                                 else if (i == numberOfColumns && found==false)
                                                           String columnValue = rs.getString(i);
                                                           if(columnValue=="a")
                                                                incrementCusta();
                                                           else if (columnValue=="b")
                                                                incrementCustB();
                                                           else if(columnValue=="c")
                                                                incrementCustc();
                                                           else if(columnValue=="d")
                                                                incrementCustId();
                                            System.out.println("");     
                                       st.close();
                                       con.close();
                                      } catch(Exception ex) {
                                           System.err.print("Exception: ");
                                           System.err.println(ex.getMessage());
                                 }

    Maybe 851.0 is float value, not string.
    Try Object columnValue1 =
    rs.getObject(i); instead of String
    columnValue1 = rs.getString(i);
    You are absolutely right i actually change the line
    custNo =Integer.parseInt(columnValue1);
    into
    custNo =Double.parseDouble(columnValue1);
    Thanks alot :)

  • How to  read from excel file and write it using implicit jsp out object

    our code is as below:Please give us proper solution.
    we are reading from Excel file and writing in dynamicaly generated Excel file.it is writing but not as original excel sheet.we are using response.setContentType and response.setHeader for generating pop up for saveing the original file in to dynamically generated Excel file.
    <%@ page contentType="application/vnd.ms-excel" %>
    <%     
         //String dLoadFile = (String)request.getParameter("jspname1");
         String dLoadFile = "c:/purge_trns_nav.xls" ;
         File f = new File(dLoadFile);
         //set the content type(can be excel/word/powerpoint etc..)
         response.setContentType ("application/msexcel");
         //get the file name
         String name = f.getName().substring(f.getName().lastIndexOf("/") + 1,f.getName().length());
         //set the header and also the Name by which user will be prompted to save
         response.setHeader ("Content-Disposition", "attachment;     filename="+name);
         //OPen an input stream to the file and post the file contents thru the
         //servlet output stream to the client m/c
              FileInputStream in = new FileInputStream(f);
              //ServletOutputStream outs = response.getOutputStream();
              int bit = 10;
              int i = 0;
              try {
                        while (bit >= 0) {
                        bit = in.read();
                        out.write(bit) ;
    } catch (IOException ioe) { ioe.printStackTrace(System.out); }
              out.flush();
    out.close();
    in.close();     
    %>

    If you want to copy files as fast as possible, without processing them (as the DOS "copy" or the Unix "cp" command), you can try the java.nio.channels package.
    import java.nio.*;
    import java.nio.channels.*;
    import java.io.*;
    import java.util.*;
    import java.text.*;
    class Kopy {
         * @param args [0] = source filename
         *        args [1] = destination filename
        public static void main(String[] args) throws Exception {
            if (args.length != 2) {
                System.err.println ("Syntax: java -cp . Kopy source destination");
                System.exit(1);
            File in = new File(args[0]);
            long fileLength = in.length();
            long t = System.currentTimeMillis();
            FileInputStream fis = new FileInputStream (in);
            FileOutputStream fos = new FileOutputStream (args[1]);
            FileChannel fci = fis.getChannel();
            FileChannel fco = fos.getChannel();
            fco.transferFrom(fci, 0, fileLength);
            fis.close();
            fos.close();
            t = System.currentTimeMillis() - t;
            NumberFormat nf = new DecimalFormat("#,##0.00");
            System.out.print (nf.format(fileLength/1024.0) + "kB copied");
            if (t > 0) {
                System.out.println (" in " + t + "ms: " + nf.format(fileLength / 1.024 / t) + " kB/s");
    }

  • Problem in reading the excel file path in WINDOWs machine from UNIX environ

    Hello friends,
    My requirement is to read each row of the excel sheet and sent that row to the database. I have implemented it by using jxl and apache poi framework. locally in my WINDOWS machine it is working fine..
    But when i deploy the code in UNIX machine. My application runs on a Unix server , trying to read the excel file in WINDOWS environment. I am not able to retrieve the file path. for ex : C:\Documents and Settings\sabbanik\My Documents\KARUNAKAR\excel.xls
    I am getting error in this line
    workbook = Workbook.getWorkbook(filepath)
    Error message : input file not found.
    Thanks in advance..

    You said: I am getting error in this line workbook = Workbook.getWorkbook(filepath) >
    Based on this, I will assume you are trying to use OLE to access information about the Excel file. As mentioned by Andreas, your code will be executing on the server (Unix) and since Excel isn't on the server (and cannot be) an error will result. OLE can only be used in Windows environments (client or server). To access client side OLE calls and content, you need a java bean and Excel installed on the client machine. Oracle provides WebUtil as an option to writing your own Java Bean. To use this, you will need to be running Forms 10.1.2 or newer. Details can be found here along with a demo:
    http://www.oracle.com/technetwork/developer-tools/forms/webutil-090641.htm

  • Store data in mysql after reading from excel files

    i am trying to make o program where i will read the data from excel files and i will store them in a database. I am using eclipse as editor and mySQL. I am using APACHE POI to read the excel files and JDBC for the connection. The excel files have the structure as shown below:
    ID NAME SALARY STREET
    321 TIM 1254 14 avenue
    121 PAUL 1265 28h oktovriou
    432 NICK 4521 papaflessa
    I have of course plenty of such files which contains many more rows and columns. The purpose of my program is to read the data, create table named as the name of the excel file and the fields of each table to be the first rows of the excel file. Afterwards the values will be the rest data of the excel file. In the code below i have managed to read them, show the data in the console. Afterwrds i am trying to call a database with JDBC but there i have problem when i create the table.
    try
    String[] allFields;
    String createTableStr = "CREATE TABLE" + createTableStr
    + "(" + org.apache.commons.lang3.StringUtils.join(allFields,
    ",") + ")";
    Could anyone help me?
    Thank you in advance!:)
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.commons.lang3.StringUtils;
    import org.apache.poi.ss.usermodel.Cell;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class exam1 {
    @SuppressWarnings({ "unchecked", "unchecked" })
    static void main (String[] args) throws Exception {
    String filename = "C:\\Users\\Efi\\Documents\\test5.xls";
    List sheetData = new ArrayList();
    FileInputStream fis = null;
    try {
    fis = new FileInputStream(filename);
    HSSFWorkbook workbook = new HSSFWorkbook(fis);
    HSSFSheet sheet = workbook.getSheetAt(0);
    Iterator rows = sheet.rowIterator();
    while (rows.hasNext()) {
    HSSFRow row = (HSSFRow) rows.next();
    Iterator cells = row.cellIterator();
    List data = new ArrayList();
    while (cells.hasNext()) {
    HSSFCell cell = (HSSFCell) cells.next();
    data.add(cell);
    sheetData.add(data);
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if (fis != null) {
    fis.close();
    showExcelData(sheetData);
    @SuppressWarnings("unused")
    HashMap<String, String> tableFields = new HashMap();
    for (int i=0; i<sheetData.size();i++){
    List list = (List) sheetData.get(i);
    for (int j=0; j<list.size(); j++){
    Cell cell = (Cell) list.get(j);
    if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
    System.out.print(cell.getNumericCellValue());
    }else if(cell.getCellType()==Cell.CELL_TYPE_STRING) {
    System.out.print(cell.getRichStringCellValue());
    } else if(cell.getCellType()==Cell.CELL_TYPE_BOOLEAN) {
    System.out.print(cell.getBooleanCellValue());
    if (j < list.size() - 1) {
    System.out.print(", ");
    private static void showExcelData(List sheetData) {
    @SuppressWarnings("unchecked")
    private HashMap parseExcelData (List sheetData){
    HashMap<String,Integer> tableFields = new HashMap();
    List list = (List) sheetData.get(0);
    for (int j=0; j<list.size(); j++){
    Cell cell=(Cell) list.get(j);
    tableFields.put(cell.getStringCellValue(),cell.getCellType());
    return tableFields;
    @SuppressWarnings({ "unchecked", "unchecked", "unchecked", "unchecked", "unused" })
    private String getCreateTable(String tablename, HashMap<String, Integer> tableFields){
    Iterator iter = tableFields.keySet().iterator();
    String str="";
    String[] allFields = new String[tableFields.size()];
    int i = 0;
    while (iter.hasNext()){
    String fieldName = (String) iter.next();
    Integer fieldType=(Integer)tableFields.get(fieldName);
    switch (fieldType){
    case Cell.CELL_TYPE_NUMERIC:
    str=fieldName + "INTEGER";
    break;
    case Cell.CELL_TYPE_STRING:
    str= fieldName + "VARCHAR(255)";
    break;
    case Cell.CELL_TYPE_BOOLEAN:
    str=fieldName + "INTEGER";
    break;
    allFields[i++]= str;
    return str;
    public Connection getConnection() throws SQLException {
    try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/kainourgia","root", "root");
    Statement stmt = con.createStatement();
    try
    System.out.println( "Use the database..." );
    stmt.executeUpdate( "USE kainourgia;" );
    catch( SQLException e )
    System.out.println( "SQLException: " + e.getMessage() );
    System.out.println( "SQLState: " + e.getSQLState() );
    System.out.println( "VendorError: " + e.getErrorCode() );
    try
    String[] allFields;
    String createTableStr = "CREATE TABLE" + createTableStr
    + "(" + org.apache.commons.lang3.StringUtils.join(allFields,
    *",") + ")";*
    System.out.println( "Create a new table in the database" );
    stmt.executeUpdate( createTableStr );
    catch( SQLException e )
    System.out.println( "SQLException: " + e.getMessage() );
    System.out.println( "SQLState: " + e.getSQLState() );
    System.out.println( "VendorError: " + e.getErrorCode() );
    catch( Exception e )
    System.out.println( ((SQLException) e).getSQLState() );
    System.out.println( e.getMessage() );
    e.printStackTrace();
    return null;
    }

    Please don't multipost! Also crossposted: http://www.java-forums.org/jdbc/71612-store-data-mysql-after-reading-excel-files.html
    Mod: I'm locking this thread.

  • CLIENT_OLE2 date formatting problem while reading from Excel

    I have installed webutil package and tested that everything works by running webutil_demo as well as WU_TEST_106 form. Then I had implemented reading from Excel sp. sheet using Oracle note 813535.1 (This note has OLE2 code sample on how to read an Excel file). Everything fine till now. The problem started when I have a date fiield to read from Excel. The field where the value is going to has format mask of 'DD-MM-RRRR'. When the date is displayed in the form, it shows '01-AUG-0009' instead of '01-AUG-2009'. I tried changing the date format to different formats in Excel but no go. I found one blog which stated that treat the date as number and use e.g. "cell_date_value:=to_date('01/01/1900','DD/MM/YYYY')+client_OLE2.get_num_property(cel,,'Value')+2" but it too did not change the display. Then I tried debugging and stepping through the code..the only thing I noticed that OLE2 function displayed the date with 2 digit year as 09 and when the code completed execution, the date went back to '01-AUG-0009'. Casting with 4 digit year at every step in the code is not helping to change final date display correctly. Any idea?!!!

    Hi,
    While reading the date column from excel, try using
         m_col_val := OLE2.get_char_property(Workcell,'Text');
    Instead of
         m_col_val := OLE2.get_char_property(Workcell,'Value');
    I think you problem will be solved...
    hello...i meant client_OLE2
    Regards
    Dora
    Edited by: Dora on Sep 16, 2009 11:05 AM

  • *** Reading from a file with tags ***

    Hi guys,
    I don't know if it is possible, but can you read from a file that contains tags?
    For example, say i want to write a simple program that just outputs the details of a person that it reads in from someFile.dat
    someFile.dat
    <DETAILS>
    <NAME> Napolean Solo </NAME>
    <ADDRESS> 10 Some Street, SomePlace </ADDRESS>
    <PHONE> 33333 </PHONE>
    <NAME> Illya Kuryakin </NAME>
    <ADDRESS> 12 Some Street, SomeOtherPlace </ADDRESS>
    <PHONE> 44444 </PHONE>
    </DETAILS>
    So what i want is program that outputs to the screen like:
    Napolean Solo
    10 Some Street, SomePlace
    33333
    Illya Kuryakin
    Is this possible in Java?????
    I really appreciate any help that is given,
    thanks in advance :)

    So what i want is program that outputs to the screen
    like:
    Napolean Solo
    10 Some Street, SomePlace
    33333
    Illya Kuryakin
    ...If that's all you want (and since a valid xml file has to start with at least <?xml version="1.0"?> so XML is irrelevant to this discussion) then this will generate the output you specify from the imput you provided:import java.io.*;
    import java.util.StringTokenizer;
    public class SimpleAngleBracketEliminator {
      public static void main (String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new FileReader(args[0]));
        String line;
        while ((line=in.readLine())!=null) {
          StringTokenizer st = new StringTokenizer(line, "<>");
          while (st.hasMoreTokens()) {
            st.nextToken();
            if (st.hasMoreTokens()) {
              System.out.print(st.nextToken().trim());
          System.out.println();
    }But if you actually want the benefits of real XML, then use a real XML parser.
    Pete

  • Read from spreadsheet file with multiple delimiters

    Is there a way to specify multiple delimitors in the read from spreadsheet file vi? I have a file that i need to read in that contains both space and comma delimitors and would like to read that data into an array using both delimitors (or not and). Below is the data I'm trying to read.
    ;attenuator data table
    att00:   db       000h,015h,017h,035h,03Ch,03Eh,03Eh,05Ch,05Eh,05Eh
    att10:   db       07Ch,07Eh,07Fh,09Dh,09Fh,09Fh,0BDh,015h,017h,035h
    att20:   db       03Eh,03Eh,05Ch,05Ch,05Eh,07Ch,07Ch,07Eh,09Dh,09Dh
    att30:   db       09Fh,0BDh,000h,000h,000h,002h,002h,002h,002h,003h
    att40:   db       021h,021h,021h,021h,021h,023h,023h,023h,023h,023h
    att50:   db       041h,041h,048h,048h,048h,04Ah,04Ah,04Ah,04Ah,068h
    att60:   db       068h,068h,068h,068h,068h,06Ah,06Bh,06Bh,06Bh,089h
    att70:   db       089h,089h,089h,08Bh,08Bh,08Bh,08Bh,0A9h,0A9h,0A9h
    att80:   db       0A4h,0A6h,0A6h,0A6h,0A6h,0C4h,0C4h,0C4h,0C4h,0C6h
    att90:   db       0C6h,0C6h,0C6h,0E4h,0E4h,0E5h,0E5h,0E7h,0E7h,0E7h
        END
    I'm looking to just read in the data adjust the hex values and then save the data in the exact form which I read it in. If read from spreadsheet file can not recognize multiple delimiters that is all I need to know. I do not want to spend time reading it in using a single delimitor and doing a bunch of string manipulation. I'm also working with LabView 8.5 if that makes a difference.

    You should use "scan string for tokens", and wire an array of delimiters.
    One nice behavior is the fact that consecutive delimiters are contracted into one (by default), so e.g. if your delimiters is an array containing a space and a comma, a sequence of three spaces and a comma would still count as one delimiter.
    For some ideas, have a look at my old example here:
    http://forums.ni.com/ni/board/message?board.id=170&message.id=192847#M192847
    LabVIEW Champion . Do more with less code and in less time .

  • Read from excel file stops at column 5(E) returns error at data variant function

    hi,
    i am read an excel file approx 15 rows by 16 rows.
    The vi works fine upto 5 rows and 5 columns and prints data on front panel after using data variant.
    The Cell range are also seems to be correct for higher rows/columns but then the errors occurs at data variant to 2d dbl stage.
    Any idea what might be wrong in the vi
    Thanks
    chintan

    Thanks for the reply.
    I found out what was wrong the data types should be the string type and i was using DBL.

  • BO Data Services - Reading from excel file and writing to SQL Server Table

    Hi,
    I would like to read data from an excel file and write it to a SQL Server Data base table without making any transformations using Data Services. I have created an excel file format as source and created target table in SQL Server. The data flow will just have source and target. I am not sure how to map the columns between source and target. Appreciate your quick help in providing a detailed steps of mapping.
    Regards,
    Ramesh

    Ramesh,
    were you able to get this to work? if not, let me know and I can help you out with it.
    Lynne

  • Read from Excel file in SP2013

    Hi,
    I have a requirement to read data from a formatted Excel file which is located in a document library, and put the contents in a List via code. This functionality should check - if he record exists  update the list item, if not create a new list
    item.
    I have installed the PIA assemblies and have referenced the excel iterop services dll from
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Excel.dll
    I am trying to use the excel interop services but getting the below error :
    public void readexcelfromExcelOp()
    using (ClientContext clientContext = new ClientContext("http://development002/"))
    List docList = clientContext.Web.Lists.GetByTitle("MDRDocuments");
    lblstatus.Text = " got the document library ";
    Excel.Application xlApp = new Excel.Application();
    Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"D:/C.xlsx");
    Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
    Excel.Range xlRange = xlWorksheet.UsedRange;
    int rowCount = xlRange.Rows.Count;
    int colCount = xlRange.Columns.Count;
    for (int i = 1; i <= rowCount; i++)
    for (int j = 1; j <= colCount; j++)
    lblExcel.Text = xlRange.Cells[i, j].Value2.ToString();
     Error 1 at the above highlighted section of the code -  One or more types required to compile a dynamic expression cannot be found. Are you missing a reference? 
    Pallavi Sharma http://letsgetalittletechnical.blogspot.com/

    You might want to look at Excel Services and use the .../_vti_bin/ExcelRest.aspx
    http://msdn.microsoft.com/en-us/library/ee556820.ASPX
    This will allow an ajax call in the browser or web request to return Xml.  To ease access to content within Excel file setup Named Ranges.  http://development002/_vti_bin/ExcelRest.aspx/MDRDocuments/c.xlsx/model/Ranges('MyNamedRange')
    Hope this helps. 
    If looking to access Excel server-side use the OpenXML API, but avoid
    accessing the physical hard drive; put the Excel document in SharePoint.

  • Problem using read from spreadsheet file and polar plotting

    Hi to all labview users,
    i am a beginner in labview and i am trying to do a polar plot.
    i read the polar plotting example in labview and it was straightforward.
    I used "write to spreadsheet file" to gather data.
    and they are in the following format
    13  10
    4  20
    8 30
    ....etc
    now. i tried using "read from spreadfile" to get the data into a array, then using "array to cluster" to convert the array into cluster, so i could connect it to the polar plot block
    however, it kept saying i couldnt connect that way, because polar plot uses 1-d array with cluster of 2 element and my source is a cluster of 9 elements....
    but doesnt the "read from spreadfile" block give me a 1-d array? and where does that 9 come from? i only have 3 rows and 2 columns in my data file....
    any guidance would be greatly appreciated.
    thx alot
    Happy guy
    ~ currently final year undergraduate in Electrical Engr. Graduating soon! Yes!
    ~ currently looking for jobs : any position related to engineering, labview, programming, tech support would be great.
    ~ humber learner of LabVIEW lvl: beginner-intermediate

    Helllo,
    I've made an example to try to help you  with that question.
    Notes:
     - the file must have values separeted by tab
     - reading the values from file as you mentioned using "read from spreadfile" you'll get a 2D array and not 1D;
    Software developer
    www.mcm-electronics.com
    PS: Don't forget to rate a good anwser ; )
    Currently using Labview 2011
    PORTUGAL
    Attachments:
    Read Table and plot polar graph.vi ‏26 KB
    teste.txt ‏1 KB

  • Problem while reading from text file using JDeveloper 10.1.2

    Hi,
    I am using JDeveloper 10.1.2 for my application. In this, I have one requirement to read some data from a text file. For that, I created a test file and saved along with the java file folder. From there, I am trying to read this file but it says the file not found exception.
    Application is looking the file from another location. "F:\DevSuiteHome_1\jdev\system10.1.2.1.0.1913\oc4j-config"
    But, I want to read it from my home folder. How is it possible to read from that location?
    Regards,
    Joby Joseph

    HI,
    Check followings will useful
    How to read .txt file from adfLib jar at model layer using relative path
    Accessing physical/relative path from Bean

  • How to read an excel file with unknown fields

    Hi,
    I am trying to import data from an Excel file through java.. [Netbeans as the IDE] I got this sample running code online [http://rgagnon.com/javadetails/java-0362.html] which was very helpful.. but i want to read from an excel file even if i dont know the fields in it.. Is this possible somehow?

    Google "POI HSSF" and or "Andy Khan jxl"
    Edit: If you insist on using the bridge, then take a look at the DatabaseMetaData class, or do a select * and look at the ResultSetMetaData class, although you are much better off not trying to use a Spreadsheet as a database, it isn't one, after all.

Maybe you are looking for