Reading from Excel sheet
I am trying to read a single column of data from an Excel sheet.
My Excel looks like this:
appnum
100
200
abc201
300
def301
400
500
My Excel sheet is called "appnumbers.xls" and the sheet is also called "appnumbers".
I have created the DSN and called it "appnumbers".
This is my code:
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
public class readExcel
public static void main( String [] args )
Connection c = null;
Statement stmnt = null;
try
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection( "jdbc:odbc:appnumbers", "", "" );
stmnt = c.createStatement();
String query = "select appnum from [appnumbers$]";
ResultSet rs = stmnt.executeQuery( query );
System.out.println( "Found the following app numbers:" );
while( rs.next() )
System.out.println( rs.getString( "appnum" ) );
catch( Exception e )
System.err.println( e );
finally
try
stmnt.close();
c.close();
catch( Exception e )
System.err.println( e );
}The output is as follows:
100.0
200.0
null
300.0
null
400.0
500.0
1. Why do the numbers appear like integers (100 shows up as 100.0)?
2. Why do the aplhanumeric characters appear as null?
Yeah, the excel odbc driver tries to gues the type of each column, based on the type of the first "data row" in each column. It's smart enough to ignore column headers, but it's not smart enough to read the whole column of values before deciding the type, so it's treating your alphanumeric values as an integer.
try sticking "abc123" in as the first data row and see what happens.
I believe, though I've never actaully done it, that you can programatically specify the datatype for each column, overriding the default silly guess work.
if that doesn't work try exporting the spreadsheet as XML and parsing it, instead of relying on the dodgy odbc driver at all.
Keith.
Message was edited by: corlettk
Similar Messages
-
Giving a specific path to the reading from excel application
Hello, i want to know there is a way of giving a specific path to an application (reading from excel sheet) without all the time getting to enter the path? if someone could help. i'm using labview 8.0
Regards,
Tchaouyou could just use a path constant. Drop a path constant on the BD and right click on it and select browse and then find the file you want.
Joe.
"NOTHING IS EVER EASY" -
Read data from excel sheet and then perform the required operations.
Hi all
I need to write a procedure which can read data from excel sheet.I have excel sheet in which i have to options one is modification and other is addition.so if it reads modification then i need to read the concerned table name then check its availability in pl-sql datbase.If table exists then reading the realated column in that row to fire the querry. The excel sheet is saved in local disk c.
can anybody help me with this.How i need to start specialy to read the data from excel sheet saved in local disk c.
Edited by: user13334062 on Jun 30, 2010 3:45 AMHi
If you can convert the excel to a csv format, then it can be simply query from DB Creating Oracle External Tables. Best part is that you may still change the CSV using EXCEL.
Following action Points can be adopt;
*1. Convert Excel File to a csv. File Save as CSV*
*2. Create Oracle Directory* ( This has to be the location of your excel file )
SQL> Create directory mydir as 'C:\testdb'; --- "testdb" is the location folder in win for your excel sheet.
*3. Create the External Table*
SQL> create table my_ext_tab (
Field1 Datatype,
Field2 Datatype,
Field3 Datatype,
Field4 Datatype,
Field5 Datatype
Organization external
(type oracle_loader default directory mydir
access parameters (records delimited by newline fields terminated by ',')
location ('my_ext_tab.csv'))
reject limit 100;
*4. Now you can query the table "my_ext_tab"*
Select * from "my_ext_tab";
Please avoid the reformat the data column inside the spreadsheet (CSV). -
Getting short dumps while reading bulky data from excel sheet
Hi all,
We have converted our non-unicode based sap system (R/3 4.7, Windows 2003,
SQL 2000) into a unicode based system recently. We are facing two peculiar
problems for last few days.
*Problem 1 - *Whenever we want to upload the data from excel sheet, the
system throws a dump after reading about 400 entries, while last week the
same system used to read about 8000 entries in a single go.
*Problem 2 - *Also, whenever we realease a transport requst from development
containing a lot of changes, the request will reach the quality system but
without the changes. but if i ll try to import the changes into quality
system after generating more than one request containing small small
changes, they get reflected in QAS immediately. Is there any size
constraint in transporting a request fro DEV->QAS->PRD.
Please suggest some ways.
I am pasting the dump (that I am getting while data uploading from Excel).
~~~~~~~~~~~~~~~~~~
Runtime errors
MESSAGE_TYPE_X*
Occurred on
22.02.2008 at
13:21:02*
The current application triggered a termination with a short dump.
What happened?
The current application program detected a situation which really
should not occur. Therefore, a termination with a short dump was
triggered on purpose by the key word MESSAGE (type X).
What can you do?
Print out the error message (using the "Print" function)
and make a note of the actions and input that caused the
error.
To resolve the problem, contact your SAP system administrator.
You can use transaction ST22 (ABAP Dump Analysis) to view and administer
termination messages, especially those beyond their normal deletion
date.
Error analysis
Short text of error message:
Control Framework : Error processing control
Technical information about the message:
Diagnosis
An error occurred when the system tried to process the commands
from the Automation Queue on the presentation server.
There are several possible reasons for this:
- The installation of the SAP GUI on the presentation server is
faulty or obsolete.
- There is an error in the application program
- There is an error in the SAPGUI or an integrated control
Procedure
1. Make sure that you have imported the appropriate Support
Package, the current kernel, and GUI patch for the release of your
System
2. Check whether the error occurs locally on one or a few PCs, or
generally on all PCs. Note whether the error only occurs for some
users, for example because of a specific Customizing setting.
If it only occurs locally, this suggests an installation problem
with the PC. Check the installation; if necessary, reinstall the
software. In the dump, search for the SY-MSGLI field, since it may
point to the cause of the error.
3. Activate the Automation Trace (in accordance with SAP Note
158985).
4.Start the transaction and continue until the screen immediately
before the dump.
5. From the System -> Utilities menu, choose Autom. Queue,
Synchronous Processing.
The status bar of the GUI displays the text:
"Automation synchron flush mode on"
6. If you now proceed with the application, the short dump will
display the ABAP call that caused the error; the Automation Trace
will contain the error on the presentation server.
7. If necessary, load the short dump and trace files on to
sapservX, so that SAP can analyze them.
Message classe...... "CNDP"
Number.............. 006
Variable 1.......... " "
Variable 2.......... " "
Variable 3.......... " "
Variable 4.......... " "
Variable 3.......... " "
Variable 4.......... " "
How to correct the error
Probably the only way to eliminate the error is to correct the program.
You may able to find an interim solution to the problem
in the SAP note system. If you have access to the note system yourself,
use the following search criteria:
"MESSAGE_TYPE_X" C
"SAPLOLEA" or "LOLEAU02"
"AC_SYSTEM_FLUSH"
If you cannot solve the problem yourself, please send the
following documents to SAP:
1. A hard copy print describing the problem.
To obtain this, select the "Print" function on the current screen.
2. A suitable hardcopy prinout of the system log.
To obtain this, call the system log with Transaction SM21
and select the "Print" function to print out the relevant
part.
3. If the programs are your own programs or modified SAP programs,
supply the source code.
To do this, you can either use the "PRINT" command in the editor or
print the programs using the report RSINCL00.
4. Details regarding the conditions under which the error occurred
or which actions and input led to the error.
System environment
SAP Release.............. "620"
Application server....... "nhbho930"
Network address.......... "192.168.0.30"
Operating system......... "Windows NT"
Release.................. "5.2"
Hardware type............ "4x Intel 801586"
Character length......... 16 Bits
Pointer length........... 32 Bits
Work process number...... 0
Short dump setting....... "full"
Database server.......... "NHBHO930"
Database type............ "MSSQL"
Database name............ "DEV"
Database owner........... "dev"
Character set............ "C"
SAP kernel............... "640"
Created on............... "Aug 17 2007 00:18:58"
Created in............... "NT 5.0 2195 Service Pack 4 x86 MS VC++ 13.10"
Database version......... "SQL_Server_8.00 "
Patch level.............. "196"
Patch text............... " "
Supported environment....
Database................. "MSSQL 7.00.699 or higher, MSSQL 8.00.194"
SAP database version..... "640"
Operating system......... "Windows NT 5.0, Windows NT 5.1, Windows NT 5.2,
Windows NT 6.0"
User, transaction...
Client.............. 300
User................ "NHBABAP"
Language key........ "E"
Transaction......... "SE38 "
Program............. "SAPLOLEA"
Screen.............. "SAPMSDYP 0010"
Screen line......... 0
Information on where terminated
The termination occurred in the ABAP program "SAPLOLEA" in
"AC_SYSTEM_FLUSH".
The main program was "ZBDC_CONTRACT ".
The termination occurred in line 29 of the source code of the (Include)
program "LOLEAU02"
of the source code of program "LOLEAU02" (when calling the editor 290).
~~~~~~~~~~~~~~~~~~~~~
Thank you all.
Cheers.
Mitra __.____._for the 50 millionth time: Excel spreadsheets are NOT databases, you should NOT try to use them as such and NEVER access them using JDBC.
You should also under NO condition use the JDBC-ODBC bridge driver (that was actually the 78 millionth time that was told someone). -
Problem in reading data from Excel sheet to 2D string array (ActiveX & LabView).
I am trying to read data from Excel sheet to 2D string array (ActiveX & LabView). Error -2147352571 is generated (type mismatch) if cell value is "#NULL!", "#N/A" etc. What should I do?
Hello �
Is the error happening when the cell value is #NULL or #NA only?
Sometimes these errors occur because of an ActiveX object mismatch. The version of the ActiveX object might have changed or been updated since the VI was created. The VI tries to use an earlier, incompatible version of the ActiveX object.
To solve the problem, you need to link automation refnum terminal to the correct ActiveX object. To do so, right-click an automation refnum terminal and choose Select ActiveX Class»Browse from the shortcut menu. From the Type Library pull-down menu, select the latest version of the library you want to use, such as Microsoft Excel Object Library. In the Objects list, select an ActiveX object, and click the OK button. Link ea
ch automation refnum terminal in the VI and its subVIs until the run arrow is not broken. Also, you might have to replace some or all of the Invoke Nodes and Property Nodes for the ActiveX objects.
Also, I came across this Knowledgebase. The error number is slightly different but it is always good to check it out and make sure it is not your case.
Hope this helps.
S Vences
Applications Engineer
National Instruments -
How to get data from excel sheet present in the client(local) system?
hi,
I have to upload the data from an excel sheet present in the local system(not on the server) to the table using webdynpro.
i donot want to upload the excel file
if it is necessary to upload the file then it should be on temporary basis and it should be deleted automatically.
i can get the data from excel sheet which is present in the km using HSSF api but how to do the same if it is in local system?
if anyone has the sample application of this type please give me the link.
thanksYou can use the FM ALSM_EXCEL_TO_INTERNAL_TABLE with Web Dynpro ABAP.
-
Mass creation of PO from excel sheet
Dear all
Kindly let me know the method for Mass creation of PO from excel sheet
Regards
Chandra mohanHi, check these links....
/people/hema.rao/blog/2006/09/14/lsmw--step-by-step
http://www.sap-img.com/sap-data-migration.htm
get more from first thread......... -
BAPI for automatic Pr creation witth multiple files from excel sheet
I have written a programm for automatic PR creation with the help of bapi , where its picks data from excel sheet and makes PR .It is picking excel files from one folder(Files) for PR creation and moving to another folder(Files sucess).
now the problem is if Folder (Files) contains one excel sheet ,PR is created fine , but if the Folder(Files) have multiple excel sheet ,its is creating 1st PR right, but next PR's contains all the line item of 1st PR , 2nd PR and so on .can anyone suggest me where is the problem in codes.
types : begin of x_file ,
key1(10),
pur_grp(4),
maktx(40),
plant(4) ,
req(10),
s_qty(13),
wbs(24),
gl(10),
trackno(10),
supl(4),
deladd(255).
types : end of x_file .
data : str5 type char10.
data : mm type char2.
data : yyyy type char4.
data : dd type char2.
data : str9 type char10.
data : str6 type char10.
data : month type char2.
data : year type char4.
year = sy-datum+0(4).
month = sy-datum+4(2).
dd = sy-datum+6(2).
yyyy = sy-datum+0(4).
mm = sy-datum+4(2).
dd = sy-datum+6(2).
clear str6 .
clear str5.
concatenate dd'.' month '.' year into str5 .
concatenate yyyy mm dd into str6 .
DATA : file type rlgrap-filename .
data : it_file type table of x_file .
data : wa_file type x_file .
data : it_header type table of x_file .
data : wa_header type x_file .
*& Internal Table For Define Row and Coloum Postion
data: col_start type i value 1 ,
row_start type i value 2,
col_end type i value 256 ,
row_end type i value 65000 .
*& Internal Table For Retrieve Data From Excel
*data: excel_bdcdata like kcde_cells occurs 0 with header line.
*data: excel_bdcdata1 like kcde_cells occurs 0 with header line.
data: excel_bdcdata like ALSMEX_TABLINE occurs 0 with header line.
data: excel_bdcdata1 like ALSMEX_TABLINE occurs 0 with header line.
data: it_index type i.
DATA : IT_INDEX1 TYPE I.
*& Define Field Symbol
field-symbols: <fs> .
data : bdcdata like bdcdata occurs 0 with header line.
data : messtab like bdcmsgcoll occurs 0 with header line.
data : req_items type table of bapiebanc .
data : wa_req_items type bapiebanc .
data : req_acc_asg type table of bapiebkn.
data : wa_req_acc_asg type bapiebkn.
DATA : RETURN LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE .
*data : return type table of bapireturn.
*data : wa_return type bapireturn .
data : number type ebeln .
*****************************MOVE FILES******************************
data : xsource type string .
data : xdestin type string .
data : destin1 type string .
data : destin2 type string .
DATA : DEST1 TYPE STRING.
DATA : DEST11 TYPE STRING.
DATA : DEST2 TYPE STRING.
DATA : DEST22 TYPE STRING.
data : sou_dir_name like SALFILE-LONGNAME.
data : tar_dir_name like SALFILE-LONGNAME.
data : tar_dir_name1 like SALFILE-LONGNAME.
data : sou_filename like EDI_PATH-PTHNAM .
data : tar_filename like EDI_PATH-PTHNAM .
data : filename1 type string .
data : tar_filename1 like EDI_PATH-PTHNAM .
data : file_itab like SALFLDIR occurs 0 with header line.
data : wa_file_itab like SALFLDIR.
data : file_count type i .
data : dir_count type i.
data : dir_table like sdokpath occurs 0 with header line.
data : file_table like SDOKPATH occurs 0 with header line.
data : wa_file_table like sdokpath.
data : strr type string ,
str1 type string ,
str2 type string ,
str3 type string .
DATA : PA_VAL TYPE CHAR1.
sou_dir_name = 'D:\barcodes\files\'.
tar_dir_name = 'D:\barcodes\files-success\'.
"success folder.
CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
EXPORTING
DIRECTORY = sou_dir_name
FILTER = '.'
IMPORTING
FILE_COUNT = file_count
DIR_COUNT = dir_count
TABLES
FILE_TABLE = file_table
DIR_TABLE = dir_table
EXCEPTIONS
CNTL_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
loop at file_table into wa_file_table.
clear : strr , str1 , str2 , str3 .
strr = wa_file_table-PATHNAME .
concatenate sou_dir_name strr into str1 .
concatenate tar_dir_name strr into str2 . " success
concatenate tar_dir_name1 strr into str3 . " failed
FILE = STR1 .
*start-of-selection.
*& Function For Retrieve Data From Excel
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = FILE
i_begin_col = col_start
i_begin_row = row_start
i_end_col = col_end
i_end_row = row_end
tables
intern = excel_bdcdata
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF sy-subrc NE 0.
WRITE : / 'File Error'.
EXIT.
ENDIF.
loop at excel_bdcdata.
translate excel_bdcdata to upper case .
move excel_bdcdata-col to it_index.
assign component it_index of structure wa_file to <fs> .
move excel_bdcdata-value to <fs>.
at end of row.
append wa_file to it_file .
clear wa_file.
endat.
endloop.
sort it_file by key1. "pur_grp maktx plant .
it_header[] = it_file[].
delete adjacent duplicates from it_header comparing key1 pur_grp maktx
plant .
data : h_item(5) type n .
data : h_pack(10) type n .
data : line_no(5) type n .
data : ln_no(5) type n .
loop at it_header into wa_header .
ln_no = 1.
h_item = h_item + 10.
h_pack = h_pack + 1.
wa_req_items-preq_item = h_item .
wa_req_items-doc_type = 'BOM'.
wa_req_items-pur_group = wa_header-pur_grp .
wa_req_items-MATERIAL = wa_header-maktx .
wa_req_items-plant = wa_header-plant .
wa_req_items-pckg_no = h_pack .
wa_req_items-deliv_date = str6 .
wa_req_items-item_cat = '0'.
wa_req_items-acctasscat = 'P'.
*wa_req_items-distrib = '2' .
**wa_req_items-gr_ind = 'X'.
wa_req_items-ir_ind = '2'.
wa_req_items-purch_org = 'TISL' .
wa_req_items-QUANTITY = wa_header-s_qty.
wa_req_items-PREQ_NAME = wa_header-req.
wa_req_items-SUPPL_PLNT = wa_header-supl.
wa_req_items-trackingno = wa_header-trackno.
append wa_req_items to req_items .
clear wa_req_items.
wa_req_acc_asg-preq_item = h_item .
wa_req_acc_asg-g_l_acct = wa_file-gl .
WA_req_acc_asg-wbs_elem = wa_header-wbs .
append wa_req_acc_asg to req_acc_asg .
clear wa_req_acc_asg.
h_pack = h_pack + 1 .
endloop.
clear ln_no .
***BREAK-POINT.
*& BAPI FUNCTION
call function 'BAPI_REQUISITION_CREATE'
importing
number = number
tables
requisition_items = req_items
requisition_account_assignment = req_acc_asg
return = return .Can someone please give me sol........
-
Hi,
I want to create a visual webpart which will read data from excel sheet and import it in to sql server database.(using sharepoint development)
I want to do it using visual webpart.
Please help to solve the issue.
Thanks in advance!
Regards
RajniHi Rajni,
Microsoft.Office.Interop.Excel assembly provides class to read excel file data, in your web part solution, reference the assembly, and following blog contains samples about how to read the excel file data,
and import it to SQL database.
1.Create a Visual Web Part Project:Create
Visual Web Parts in SharePoint 2010
2.Read the excel workbook by using SPFile class:
http://alancejacob.blogspot.in/2012/06/read-data-from-excel-file-and-insert-in.html
http://stackoverflow.com/questions/14496608/read-excel-file-stored-in-sharepoint-document-library
3.Export the excel workbook to SQL Server:
http://www.c-sharpcorner.com/UploadFile/99bb20/import-excel-data-to-sql-server-in-Asp-Net/
Best Regards,
Eric
Eric Tao
TechNet Community Support -
Unable to export more than 19 rows of data from Excel sheet
Anyone could please guide me how to export more data from excel sheet.
I tried with 50 row but only 19 rows are exported.
Appln builder==> create ==> Export from spread sheet --> Copy paste / csv export (i tried both) but i got only 19 rows.
Regards,
ManojHi Manoj,
If you're talking about the 19 rows you see while in the create wizard, that is just a sample of the data so you can see what you're working with while specifying column names, types, etc. Once you finish working in the wizard it should import all of the rows assuming there aren't any error-rows.
Hope this helps,
John
If you find this information useful, please mark the post "helpful" or "correct" so that others may benefit as well.* -
hi sir i am read excel sheet using labview ,but unable to plot the selected colomns,so its needfull ,please find any body to sollution to the problem .i i already did some part ,it is take too much delay
Attachments:
CSV File to XY GRAPH 13.lvproj 9 KBshambhulinga a écrit :
hi sir i am read excel sheet using labview ,but unable to plot the selected colomns,so its needfull ,please find any body to sollution to the problem .i i already did some part ,it is take too much delay
First, you are not reading an Excel sheet but a text file (a csv file is a text file). From the listing of the function used (from the lvproj file) you are using the Read From Spreadsheet function, this function will return a 2D array. Use the Index Array function to extract the x and y value columns. Bundle them (using the Bundle function) and wire the output to your XY-Graph.
Ben64 -
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 -
Import of activity list from Excel sheet.
Dear all,
I have configered PS module and is working fine.
I have some existing data of activities in Excel sheets. Which are around 2000 activies for every project.
I want to directly imports these activiteis from Excel sheet to SAP activity list.
IS there any method by with I can upload these activities from Excel file directly.
Regards
SCSharmafirst create a BDC (or record LSMW) and rearrange your excel sheet as per BDC requirement and upload...!
-
.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 AdvanceYou need database drivers to read excel spread sheets?
Also, why did you make it an exe? just jar it and be done with it. -
How to retrieve data from excel sheet
Hi,
How to retrieve data from excel sheet into a java file.janu05 wrote:
If we append a $ in the end of the table name it is showing an error saying "invalid name,should not contain any invalid character or punctuation"Great, I'm very happy for you.
Unless that was a question. In which case you might what to tell us a little more.
Like which API you are using (assuming we are still on "reading an Excel sheet".
Maybe you are looking for
-
I'd previously posted an issue about not being able to edit blog comments in iWeb. They appeared on the blog, but did not appear in iWeb. I recently updated to 3.0.2 and it finally fixed that problem, but my main blog page is no longer showing photos
-
Pics don;t open in the Edit window when double clicked
Hi Need some help please. I had some problems with iPhoto and after trying to rebuild it etc etc etc, decided to reinstall everything. I backed up the entire library to a DVD, deleted the current library and then created a new one. Placed DVD in driv
-
My users and I have noticed that PICT images with alpha channels are not being displayed properly after the update to QuickTime 7.4. The images neither display properly in the Finder preview nor in Preview itself. For me, this involves PICT image dis
-
Sorting XMLListCollection by nested elements
I've been sorting XML files using an XMLListCollection when I have an XML with the following structure: <products> <product id="1"> <field1>value</field1> <field2>value</field2> <field3>value</field3> </product
-
Can't get my pic what to do?
your program does not let me in i need help and i don't want to loose my pic