How to mail excel file as an attachment daily...
Dear BOBJ Experts,
I have an excel located in my server . I would like to mail this excel as an attachment to the recipients . This is a daily activity.
Is this possible with mailer.exe . What is the difference between mailer.exe and smtp_mailer.exe ?
Any thoughts will be appreciated.
Thanks and regards,
Dirasa
Dear Prashanth,
I would like to make use of MAILER.EXE to send mail with attachment to the set of users.
Following code works fine in cmd prompt and the mail is deliverable with no errors.
mailer.exe -t'mailid' -v .
I created a bat file with the above script and i tried to execute the bat file using script.
But it is throwing the following error.
Function <exec> failed to execute program <C:\Program Files\Business Objects\BusinessObjects Data Services\bin\MAIL.BAT>RUN-050306 2/1/2007 7:04:59 PM Program terminated with exit code <160117>. "
Please throw me out of this problem.
Many thanks in advance.
Regards,
Dirasanchu
Similar Messages
-
Send An Internal Table Via Excel File As An Attachment of E-mail
Hi,
I've sent my internal table via Excel file as an attachment of email but all records of internal table are in a row of sended excel file.
How can i send an internal table via excel file , records of internal table for each rows of excel file,as an attachment of email correctly?
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list " t_packing_list-doc_type = 'XLS'.
contents_bin = pit_attach " this is a normal internal table.
contents_txt = pit_message
receivers = t_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.Hi,
CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
CONSTANTS:
CON_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.
LOOP AT T_FINAL INTO WA_T_FINAL.
CONCATENATE WA_T_FINAL-PERNR
WA_T_FINAL-NAME
WA_T_FINAL-LEVEL
WA_T_FINAL-POS
WA_T_FINAL-JOB
WA_T_FINAL-SECTION
WA_T_FINAL-DEPT
WA_T_FINAL-GROUP
WA_T_FINAL-EX_HEAD
WA_T_FINAL-SUPID
WA_T_FINAL-SUPNM
WA_T_FINAL-FHRNM
WA_T_FINAL-VACID
WA_T_FINAL-VAC_SECTION
WA_T_FINAL-VAC_DEPT
WA_T_FINAL-VAC_GROUP
WA_T_FINAL-VAC_EX_HEAD
WA_T_FINAL-VAC_FHRNM
INTO T_FINAL3 SEPARATED BY CON_TAB.
CONCATENATE CON_CRET T_FINAL3 INTO T_FINAL3.
APPEND T_FINAL3.
ENDLOOP.
*Fill the document data.
W_DOC_DATA-DOC_SIZE = 1.
*Populate the subject/generic message attributes
W_DOC_DATA-OBJ_LANGU = SY-LANGU.
W_DOC_DATA-OBJ_NAME = 'REPORT'.
W_DOC_DATA-OBJ_DESCR = LD_MTITLE . "mail description
W_DOC_DATA-SENSITIVTY = 'F'.
*Fill the document data and get size of attachment
CLEAR W_DOC_DATA.
READ TABLE T_FINAL1 INDEX W_CNT.
W_DOC_DATA-DOC_SIZE =
( W_CNT - 1 ) * 255 + STRLEN( T_FINAL1 ).
W_DOC_DATA-OBJ_LANGU = SY-LANGU.
W_DOC_DATA-OBJ_NAME = 'SAPRPT'.
W_DOC_DATA-OBJ_DESCR = LD_MTITLE.
W_DOC_DATA-SENSITIVTY = 'F'.
CLEAR T_ATTACHMENT.
REFRESH T_ATTACHMENT.
T_ATTACHMENT[] = PT_FINAL1[].
*Describe the body of the message
CLEAR T_PACKING_LIST.
REFRESH T_PACKING_LIST.
T_PACKING_LIST-TRANSF_BIN = SPACE.
T_PACKING_LIST-HEAD_START = 1.
T_PACKING_LIST-HEAD_NUM = 0.
T_PACKING_LIST-BODY_START = 1.
DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.
T_PACKING_LIST-DOC_TYPE = 'RAW'.
APPEND T_PACKING_LIST.
*Create 1st attachment notification
T_PACKING_LIST-TRANSF_BIN = 'X'.
T_PACKING_LIST-HEAD_START = 1.
T_PACKING_LIST-HEAD_NUM = 1.
T_PACKING_LIST-BODY_START = 1.
DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.
T_PACKING_LIST-DOC_TYPE = LD_FORMAT.
T_PACKING_LIST-OBJ_DESCR = 'Application 1'.
T_PACKING_LIST-OBJ_NAME = 'Application 1'.
T_PACKING_LIST-DOC_SIZE = T_PACKING_LIST-BODY_NUM * 255.
APPEND T_PACKING_LIST.
CLEAR T_PACKING_LIST.
*Add the recipients email address
CLEAR T_RECEIVERS.
REFRESH T_RECEIVERS.
T_RECEIVERS-RECEIVER = LD_EMAIL.
T_RECEIVERS-REC_TYPE = 'U'.
T_RECEIVERS-COM_TYPE = 'INT'.
T_RECEIVERS-NOTIF_DEL = 'X'.
T_RECEIVERS-NOTIF_NDEL = 'X'.
APPEND T_RECEIVERS.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = W_DOC_DATA
PUT_IN_OUTBOX = 'X'
SENDER_ADDRESS = LD_SENDER_ADDRESS
SENDER_ADDRESS_TYPE = LD_SENDER_ADDRESS_TYPE
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = W_SENT_ALL
TABLES
PACKING_LIST = T_PACKING_LIST
CONTENTS_BIN = T_ATTACHMENT
CONTENTS_TXT = IT_MESSAGE
RECEIVERS = T_RECEIVERS
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8.
Edited by: Rahul Ghosh on Apr 6, 2009 6:42 AM -
Adapter Module Error-Sending excel file as an attachment of the mail
Hi ,
My scenario is as follows
1)I am sending an excel file as an attachment of the mail.I need to read that excel attachment as a payload.
So mail adapter is used in sender side.
To configure this, have used standard PayloadSwapBean module with proper module key.
Next to convert excel to XML another custom adapter module is being used.
Both this adapter module , I configured into the CC of sender mail adapter.
The order in which adapter modules are being used in the sender CC are as follows
1)localejbs/AF_Modules/PayloadSwapBean
2)localejbs/MDPExcelToXMLConversion
3)sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean
MDPExcelToXMLConversion-Custom adapter module written to convert excel to xml.
I am getting the following error
exception caught during processing mail message [4899]com.sap.aii.af.lib.mp.module.ModuleException
And also,
no messages in coming MONI of PI.
Pls suggest what to do.
Thanks
AyanShabarish,
Will the ordering in which the adapter modules(In this case there are two-PayloadSwapBean & MDPExcelToXML) are appearing into Module tab of sender adapter matter?
Firstly, what is happenning
1)If I take out the custom adapter module MDPExcelToXML and put only PayloadSwapBean then it is successfully converting mail attachment into the main Payload i.e PayloadSwapBean module is working.
2)Nextly, my local code( i.e java code without including standard Module specific method like ejbActivate(),ejbPassivate(),process() etc etc.)) for MDPExcelToXML is successfuly converting the excel file into the XML file.Then I am making the local code into adapter module specific code and deploying that.
A few question arises here,
Do I need to do any specific configurations here in PI for this particular things.Maybe both the adapter module is clashing with each other.
And also using tracing and logging into my custom adapter module code.Getting the following error,
java.io.IOException: Unable to read entire header; 116 bytes read; expected 512 bytes#
Thanks
Ayan -
Please tell me How to send excel file content to MAILBOX
Hello ,
Can anybody tell me how to send Excel file data to MailboxHi,
Check this sample code.
INITIALIZATION .
CLASS cl_abap_char_utilities DEFINITION LOAD.
gf_etb = cl_abap_char_utilities=>horizontal_tab. "For horrizontal tab
gf_cr = cl_abap_char_utilities=>cr_lf. "For enter
gf_lf = cl_abap_char_utilities=>newline. "For new line
Declaration
DATA: lwa_hd_change TYPE sood1,
lt_objcont TYPE STANDARD TABLE OF soli,
lwa_objcont TYPE soli,
lt_receivers TYPE STANDARD TABLE OF soos1,
lwa_receivers TYPE soos1 ,
lt_att_cont TYPE STANDARD TABLE OF soli,
lwa_att_cont TYPE soli,
lt_packing TYPE STANDARD TABLE OF soxpl,
lwa_packing TYPE soxpl,
lf_sent TYPE sonv-flag,
lf_size TYPE i.
CONSTANTS: lc_obj(11) TYPE c VALUE 'BOMSouthco',
lc_desc(20) TYPE c VALUE 'BOM Download',
lc_lang(1) TYPE c VALUE 'E',
lc_raw(3) TYPE c VALUE 'RAW',
lc_net(1) TYPE c VALUE 'U',
lc_mail(4) TYPE c VALUE 'MAIL',
lc_xls(3) TYPE c VALUE 'XLS',
lc_ext(3) TYPE c VALUE 'EXT'.
Passing values to the strutures used in SO_OBJECT_SEND function module
lwa_hd_change-objla = lc_lang.
lwa_hd_change-objnam = lc_obj.
lwa_hd_change-objdes = lc_desc.
lwa_hd_change-objlen = 255.
lwa_objcont-line = text-t29.
APPEND lwa_objcont TO lt_objcont.
CLEAR lwa_objcont.
lwa_receivers-recextnam = text-t31.
lwa_receivers-recesc = lc_net.
lwa_receivers-sndart = lc_mail.
lwa_receivers-sndex = 'X'.
lwa_receivers-sndpri = 1.
lwa_receivers-mailstatus = 'E'.
APPEND lwa_receivers TO lt_receivers.
CLEAR lwa_receivers.
lwa_receivers-recextnam = text-t30.
lwa_receivers-recesc = lc_net.
lwa_receivers-sndart = lc_mail.
lwa_receivers-sndex = 'X'.
lwa_receivers-sndpri = 1.
lwa_receivers-mailstatus = 'E'.
APPEND lwa_receivers TO lt_receivers.
CLEAR lwa_receivers.
Passing values for the attachment file
LOOP AT gt_output INTO gwa_output.
CONCATENATE gf_lf gwa_output-matnr gf_etb gwa_output-idnrk gf_etb
gwa_output-type gf_etb gwa_output-menge gf_etb
gwa_output-meins gf_etb gwa_output-comp gf_etb
INTO lwa_att_cont-line.
APPEND lwa_att_cont TO lt_att_cont.
CLEAR lwa_att_cont.
ENDLOOP.
CHECK lt_att_cont IS NOT INITIAL.
DESCRIBE TABLE lt_att_cont LINES lf_size.
lwa_packing-transf_bin = ' '.
lwa_packing-head_start = 1.
lwa_packing-head_num = 0.
lwa_packing-body_start = 1.
lwa_packing-body_num = lf_size.
lwa_packing-file_ext = lc_xls.
lwa_packing-objlen = lf_size * 255.
lwa_packing-objtp = lc_ext.
lwa_packing-objdes = lc_desc.
lwa_packing-objnam = lc_obj.
APPEND lwa_packing TO lt_packing.
CLEAR lwa_packing.
CHECK gf_error IS NOT INITIAL. "Check if unix file is written
FM to send email to the intended recipients
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = lwa_hd_change
object_type = lc_raw
IMPORTING
sent_to_all = lf_sent
TABLES
objcont = lt_objcont
receivers = lt_receivers
packing_list = lt_packing
att_cont = lt_att_cont
EXCEPTIONS
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
forwarder_not_exist = 6
note_not_exist = 7
object_not_exist = 8
object_not_sent = 9
object_no_authorization = 10
object_type_not_exist = 11
operation_no_authorization = 12
owner_not_exist = 13
parameter_error = 14
substitute_not_active = 15
substitute_not_defined = 16
system_failure = 17
too_much_receivers = 18
user_not_exist = 19
originator_not_exist = 20
x_error = 21
OTHERS = 22.
IF sy-subrc = 0.
MESSAGE s004 WITH text-t34.
ENDIF.
COMMIT WORK.
Reward if helpful.
Regards,
Ramya -
How to upload Excel file in BI using function module in abap program
How to upload Excel file in BI using function module in abap program?
Hi Anuj,
To upload the file , you can try a standard program "RSEPSFTP" .
while you execute the program , a selection screen appears in which the inputs should be give as
RFC destination - The target server name
FTP command- PUT
local file - your file name
local directory - path of your local file
remote file - your target file name
remote directory - where it has to be stored
Hope this is useful for you
Thanks & regards
Anju -
How to Zip Excel files using File Adapter?
Hi,
We have tried to ZIP the Excel file with PayloadZipBean in File adapter. But we faced some issue while zipping.
We have seen some zunk data in excel file after zipping with PayloadZipBean. Someone please help how to zip Excel files in PI with File Adapter.
Regards,
Sreeramulu Konjeti.Hi Sree,
If you are facing any issue with PayloadZipBean then you can use java mapping to Zip the files.
Please find the complete Java mapping code to zipt the file
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/50ce0433-4309-2b10-4bb4-d421e78463f7?quicklink=index&overridelayout=true -
How to send a file as an attachment using mailx
Hi
Can any one tel me how to send a file as an attachment using mailx command in shell script.
Thanks,
Suman.Wrong forum where to ask such questions.
Check this one link:
http://www.unix.com/shell-programming-scripting/18370-sending-email-text-attachment-using-mailx.html?t=18370#post70254 -
Sending excel file as an attachment in email program thru Oracle8i
I cant send my excel file as an attachment in my email program thru Oracle 8i.
My excel file i located in my local pc C:\test.xls
Everything is in my local machine, DB and progams.
I have read the example of DEMO_MAIL program i am hardly understand it.
My sample program:
if (p_file_name is not null) then
begin_attachment( p_mime_type=>'application/excel', p_fname=>p_file_name,
p_transfer_enc=>'base64'
dbms_lob.createtemporary(l_blob, true);
dbms_lob.open(l_bfile);
dbms_lob.fileopen(l_bfile);
dbms_lob.open(l_blob, dbms_lob.lob_readwrite);
dbms_lob.loadfromfile(l_blob, l_bfile, dbms_lob.getlength(l_bfile));
dbms_lob.fileclose(l_bfile);
dbms_lob.close(l_bfile);
l_file_len := dbms_lob.getlength(l_blob);
l_modulo := mod(l_file_len,MAX_BASE64_LINE_WIDTH);
l_pieces := trunc(l_file_len/MAX_BASE64_LINE_WIDTH);
while (l_counter < l_pieces)
loop
dbms_lob.read(l_blob, l_modulo, l_filepos, l_buffer);
l_message := utl_raw.concat(l_message, l_buffer);
write_mb_text(l_message||g_crlf);
l_filepos := l_counter * MAX_BASE64_LINE_WIDTH + 1;
l_counter := l_counter + 1;
end loop;
if l_modulo <> 0 then
dbms_lob.read(l_blob, l_modulo, l_filepos, l_buffer);
l_message := utl_raw.concat(l_message, l_buffer);
write_mb_text(l_message||g_crlf);
end if;
dbms_lob.close(l_blob);
end_attachment(true);
Please helpI did not receive any error messages when executing the program. It works fine, I received the email nicely but without the attachment.
Here is the emails I received:
LOGICAL SPACE USED HAS REACHED ITS TRESHOLD. PLEASE DO NECESSAY TO MAKE MORE ROOM FOR THE SPACE TO EXTEND.
Tablespace Name Used Size(MB) Free Size(MB)
SYSTEM 259.953 4.047
USERS 144.508 55.492
INDX 31.258 26.742
-------7D81B75CCC90D2974F7A1CBD
Content-Type: multipart/mixed; boundary="-----7D81B75CCC90D2974F7A1CBD"
Content-Disposition: attachment; filename="capacity_13-JAN-05-111226.xls"
Content-Transfer-Encoding: base64
-haris -
How to transfer excel files(on ftp server) into internal table?
hello,everyone
pls tell me how to transfer excel files those on a ftp server into internal table?
ps.i know the function 'ftp_server_to_r3',it can help to transfer flat file.Hi,
I believe you want to get the data from the FTP Server to R3.
I am also sending the code. Have a look and it would help you.
First get the Password and user name and the FTP Server Path where file is stored and FTP Server Host name
FUNCTION zfi_ftp_get.
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_FILENAME) TYPE C
*" TABLES
*" T_BLOB STRUCTURE ZFI_TLM_LENGTH OPTIONAL " is a table type with a field called line of length 992
*" RETURN STRUCTURE BAPIRET2 OPTIONAL
DATA : i_password(30) TYPE c,
i_user(30) TYPE c,
i_host(30) TYPE c,
i_rfc_destination TYPE rfcdes-rfcdest,
i_length TYPE i,
i_folder_path(100) TYPE c.
DATA: lv_blob_length TYPE i.
DATA: lv_length TYPE i, "Password length
lv_key TYPE i VALUE 26101957,
lv_password(30) TYPE c,
lv_ftp_handle TYPE i,
lv_cmd(80) TYPE c.
DATA: BEGIN OF result OCCURS 0,
line(100) TYPE c,
END OF result.
TYPES: BEGIN OF ty_dummy,
line(392) TYPE c,
END OF ty_dummy.
DATA: lt_dummy TYPE TABLE OF ty_dummy,
ls_dummy LIKE LINE OF lt_dummy.
i_password = 'vnhdh'.
i_user = 'sdkgd'.
i_host = 'sbnksbg'.
i_rfc_destination = 'SAPFTP'.
i_length = '992'.
i_folder_path = '/hioj/hohjk/hh'.
lv_length = STRLEN( i_password ).
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
SOURCE = i_password
sourcelen = lv_length
key = lv_key
IMPORTING
destination = lv_password.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = i_user
password = lv_password
host = i_host
rfc_destination = i_rfc_destination
IMPORTING
handle = lv_ftp_handle
EXCEPTIONS
not_connected = 1
OTHERS = 2.
IF sy-subrc = 1.
return-type = 'E' .
return-message = 'FTP Connection not Successful'.
APPEND return.
ELSEIF sy-subrc = 2.
return-type = 'E' .
return-message = 'FTP Connection not Successful'.
APPEND return.
ELSEIF sy-subrc EQ 0.
return-type = 'S' .
return-message = 'FTP Connection Successful'.
APPEND return.
CONCATENATE 'cd' i_folder_path INTO lv_cmd SEPARATED BY space.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = lv_ftp_handle
command = lv_cmd
TABLES
data = result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
IF sy-subrc = 1.
return-type = 'E' .
return-message = 'Command Error Occured during open of FTP Folder'.
APPEND return.
ELSEIF sy-subrc = 2.
return-type = 'E' .
return-message = 'TCIP Error Occured during open of FTP Folder'.
APPEND return.
ELSE.
REFRESH t_blob.
lv_blob_length = 992.
TRANSLATE i_filename TO LOWER CASE.
CALL FUNCTION 'FTP_SERVER_TO_R3'
EXPORTING
handle = lv_ftp_handle
fname = i_filename
IMPORTING
blob_length = lv_blob_length
TABLES
blob = lt_dummy.
t_blob[] = lt_dummy[].
ENDIF.
ENDIF.
ENDFUNCTION.
Regards
Sajid
Edited by: shaik sajid on Nov 16, 2010 7:25 AM -
Hi PI Experts,
I have a requirement File(.txt) - PI(7.4) - mail (.xls attachment and signature in the body). Can anyone pls help me with the best approach to send excel file as mail attachment and signature in the body.
Thanks,
SriHi
You can try this approach
1. use mail package and java mapping to populate the mail package.
inside the java mapping do the following
a. read the text file and convert it to excel and then set it as additional attachment.
b. map the signature and body with the field 'content' of mail package.
2. on the receiver mail adapter check both mail package and keep attachment options.
Hopefully this will work.
Reference links
excel write : Excel and Java - Read and Write Excel with Java - Tutorial
set attachment: How to save MainDocument as additonal attachment in sender channel? -
How to Create Excel File in Background processing with different colors
HI All
I am trying to create Excel file in background & send it to user through e-mail, this i could acheive using fucntion module SO_DOCUMENT_SEND_API1, but here my requirement is i want to put different colors to columns of excel & this should happen in Background processing,
Initially i completed above requirement by using HTML type of document with attachment type 'ALI' & formatted output using write statement & used colors, after that i took this o/p using save_list function module & then table compress...etc.
but i don't know how to achieve same if we need o/p in excel as size of object of excel file is less than that of HTML
I am thankfull to everybody who will help me.
Regards
LokeshLokesh,
Iam also trying to populate my text file with colors as an attachment . If you know this please let me know. -
Sending email with excel file as an attachment
Hi,
In my procedure I am creating one excel file and keeping that excel file in one location as specified in UTL_FILE_DIR.Now my requirement is to pick that excel file from that path and send it as an attachment through an Email.
Can anyone please give me the code to do that and what are the required set up to be done before sending the mail.
Please help me in this regard. This is an urgent requirement.
Thanks
SubhabrataHi,
Please refer the following link:
http://www.dbasupport.com/oracle/ora10g/10g_PLSQL02.shtml
There is para headed Sending E-Mail and Attachments with UTL_MAIL will clarify all your doubts. Link Listing 2.6
is good example.
If you get stuck while coding, get back to us.
Twinkle -
Sending an excel file as an attachment to email
Hi,
I am using FM 'SO_DOCUMENT_SEND_API1' to send an excel file to an email ID.But the mail is going to the SAP inbox and it is posting not to the external mail ID like ([email protected]).
Please suggest me on this.
Regards'
Ved.Hi
The mail sending process depends on how your company's mail server has been setup. Check the mail server setup with ur basis/network team. Moreover, go to transaction SCOT and manually trigger the mail sending process.
In this transaction check the SMTP settings if it is set to *ALL.
Moreover, try to manually trigger the send process in SCOT. There is a button called 'Start Send process'. After this check if the mails are still in your SAP Outbox. You can even trigger the send process from within your ABAP program by submitting the program RSCONN* (Try to search with this initials)
Please award points if this was helpful. -
How to read excel file in document library and store excel content in sql table
Hello,
Can anyone help me how to read the excel file present in document library and store the content inside excel into sql table?
Please let me know the ways to acheive this. Feel free to give your suggestions.
Thanks,
Cool DeveloperHi!
this code i have written becuase i donot find any soltions on net for this , u can try with this . :)
System.Data.OleDb.
OleDbConnection ExcelConnection = null;
FileMode fileMode;
string filePath = ConfigurationManager.AppSettings["TempLoaction"] + "\\" + fileName;
using (SPSite _site = new SPSite(SPContext.Current.Web.Url))
using (SPWeb _web = _site.OpenWeb())
string docLibrary = ConfigurationManager.AppSettings["DocumentLibrary"];
SPFile _file = _web.GetFile("/" + docLibrary + "/" + fileName);
fileMode =
FileMode.Create;
byte[] byteArray = _file.OpenBinary();
MemoryStream dataStream = new MemoryStream(byteArray);
Stream stream = dataStream;
using (FileStream fs = File.Open(filePath, fileMode))
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
fs.Write(buffer, 0, bytesRead);
fs.Close();
//Create the Connection String
try
string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source ='"
+ filePath + "'; Extended Properties=Excel 5.0";
//Create the connection
ExcelConnection =
new System.Data.OleDb.OleDbConnection(ConnectionString);
//create a string for the query
string ExcelQuery;
//Sheet1 is the sheet name
//create the query:
//read columns from the Excel file
ExcelQuery =
"Select * from [Sheet1$]"; // from Sheet1";
//use "Select * ... " to select the entire sheet
//create the command
System.Data.OleDb.
OleDbCommand ExcelCommand = new System.Data.OleDb.OleDbCommand(ExcelQuery, ExcelConnection);
//Open the connection
ExcelConnection.Open();
//Create a reader
System.Data.OleDb.
OleDbDataReader ExcelReader;
ExcelReader = ExcelCommand.ExecuteReader();
//For each row after the first
while (ExcelReader.Read())
thanks,
kshitij -
How to read Excel file in java
Respected sir/madam
I want to read the values from Excel file in Java program. How can I do that. When I searched over the net I came to know that you can treat Excel file as a Database and write the code as u write for making DB connections .
I did that but i am getting the following error ..can anybody please help..
This is the code what i have written
import java.io.*;
import java.sql.*;
public class ReadExcelFile {
Connection c;
Statement stmnt;
public void checkABA_Number()
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c = DriverManager.getConnection("jdbc:odbc:ExcelTest","",""); // ExcelTest is the DSN name
stmnt = c.createStatement();
ResultSet rs = stmnt.executeQuery("select * from abadata"); // abadata is my Excel file name
while(rs.next())
System.out.println(rs.getString(1)+" "+rs.getString(2));
}catch(Exception e)
System.out.println(""+e.toString());
finally
try
stmnt.close();
c.close();
catch( Exception e )
System.err.println( e );
public static void main(String[] args)
new ReadExcelFile().checkABA_Number();
My Excel file starts from the first row and first column and also the first row contains the names of the column.
It give me the following error..
java.sql.SQLException: [Microsoft][ODBC Excel Driver] The Microsoft Jet database engine could not find the object 'abadata'. Make sure the object exists and that you spell its name and the path name correctly.
How can I deal with this.?I have properly selected the worksheet while giving the DSN . Is there any versionig problem with Excel or some drivers are in appropriate..and yes i chose Microsoft Excel Driver (.xsl) from ODBC .
I created System DSN.
Can anybody please help me with this ? I will be very gratefull for replies
Thanks in advancehere is the code to read excel file
public void readexel(String filename)
Connection c = null;
Statement stmnt = null;
try
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" + filename);
stmnt = c.createStatement();
String query = "Select * from [Sheet1$]" ;
ResultSet rs = stmnt.executeQuery( query );
while( rs.next() )
System.out.println( rs.getString(1) );
catch( Exception e )
System.err.println( e );
}
Maybe you are looking for
-
Yoga 3 pro box opening problem
Dear All, I just joined the lenovo world by buying a yoga 3 pro. Unfortunately, I am having an unusual problem. I plugged in the device and tried to turn it on. It did not work. There is no picture on the screen, and there is the light getting on and
-
How can I update OS 9.0.4 to 9.2 to run Classic?
Okay some of you might remember me - like Cornelius... Basically, I just recently put OS X 10.4 on my computer to fix an earlier problem (you can read my other post if you want). To make a long story short, I put OS 9 on it again in order to get Clas
-
GNOME (Wayland) doesn't work correctly after resume
I installed Wayland, GNOME and GDM on my laptop. When I resume and unlock laptop after supend GNOME log me out. EDIT: I'll add some logs: lut 09 23:55:57 adam-laptop gnome-session[353]: OK lut 09 23:55:57 adam-laptop gnome-session[353]: Received sign
-
Hello, A terminal server rebooted itself out of nowhere and I see the following error in the eventviewer: Log Name: System Source: Microsoft-Windows-WER-SystemErrorReporting Date: 11-9-2014 9:25:38 Event ID: 1001 Task Categ
-
Hi, I have a question relating to E-Sourcing capability to publish and consume web services a) Can we create and publish new web services on E-Sourcing system. Intention is to create and publish custom web services that would enable external applicat