Read .xls-file in JSP
My problem is this:
I have a jsp page that should open a template spreadsheet and make
some changes and the show it to the user. Everthing works but I have
to put the template excel-file in the /bin directory of the server
program, tomcat. The jsp-file cannot find the file if it lies in the
main web application directory(I've tried it in the web-inf, lib and
classes directory aswell). I uses a spreadsheet api called JExcelAPI, if someone wounders...
This is the basic code I use in the jsp-file:
response.setContentType("application/vnd.ms-excel");
OutputStream excelOut = response.getOutputStream();
Workbook workbook = Workbook.getWorkbook(new File("temp.xls"));
WritableWorkbook copy = Workbook.createWorkbook(excelOut, workbook);
The problem lies on line 3 where the file is read.
I've tried it as a servlet too but the didn't fix the problem.
What am I doing wrong? Why can't the JSP file locate the temp.xls if it just lies in the web application directory?
Thanks / Daniel
Instead of:
Workbook workbook = Workbook.getWorkbook(new File("temp.xls"));
try:
Workbook workbook = Workbook.getWorkbook(new File(getServletContext().getRealPath("/temp.xls")));
Similar Messages
-
How to read .xls file from FTP server t oInternal table
Hi
am using the FTP_SERVER_TO_R3 to read xls file from FTP server to internal table
but the data i get in LT_TEXT is special characters.
CALL FUNCTION 'FTP_SERVER_TO_R3'
EXPORTING
handle = hdl
fname = f_name "ProdDataFromCRM.xls.
* CHARACTER_MODE = 'X'
* IMPORTING
* BLOB_LENGTH =
TABLES
BLOB = lt_text
* TEXT = lt_text
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4
can any one help me out to get the exact data..
Really appreciate your quick response..
Thank YouHi, if you really retrieve an excel file, you can not see the data in ABAP. You may see them in Excel. For this you may use
CALL METHOD document->open_document_from_table
of the interface i_oi_document_proxy for OLE objects. You can access the data with reference to the interface i_oi_spreadsheet.
Please check [Desktop Office Integration (BC-CI)|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIOFFI/BCCIOFFI.pdf] for details.
But, who knows, perhaps you want "And Now For Something Completely Different".
Regards
Clemens -
Hi all
I want read the content of a xls file.
For creating xls file am used poi.
On reading xls hoe to get the column and row count.
pls reply with example
thanks for reply.You're already using POI to create XLS files. Guess what, you can also use the same to read XLS files. If your problem is more that you don't know how, then just read the documentation and code examples which come along it (and are available at its homepage).
-
I'm trying to read a XLS file from a URL.
What exactly the code is trying to do is this:
User clicks on a button in a webpage for select a xls file . The file selected may be read and a method write a txt file on another server.
How can i do this?
Many thanks.Hi,
Check whether path ur providing to the open data set stmt is correct or not in debugging mode.
* File upload to internal table from UNIX Directory
IF NOT p_i1file IS INITIAL AND NOT p_path IS INITIAL.
CONCATENATE p_path p_i1file INTO v_file.
CONDENSE v_file.
OPEN DATASET v_file FOR INPUT IN TEXT MODE MESSAGE v_msg.
IF sy-subrc EQ 0.
WRITE: / 'INPUT FILE CONTAINS NO RECORD :'(010), v_file.
DO.
CLEAR tbl_input.
READ DATASET v_file INTO tbl_input.
IF sy-subrc NE 0.
EXIT.
ELSE.
APPEND tbl_input.
ENDIF.
ENDDO.
* Close Input File
CLOSE DATASET v_file.
ELSE.
WRITE:/'Error uploading file: '(008),v_file.
STOP.
ENDIF.
ENDIF.
It should work.check the sy-subrc value and file value in debug mode.
Thanks
Parvathi -
Problem reading .xls file from App Server
Hi Everyone......
I hope this might be a common problem but i searched for similar problem......i did'nt find the solution my problem is
I'm trying to download .xls(excel file data into an internal table using OPEN DATASET FOR INPUT IN TEXT MODE ENCODING DEFUALT and read dataset for reading it).But in the read dataset syntax all stange values like **$#@&&& are getting uploaded???? I dont now why......
Is it happing because i'm trying to upload .XLS file ???
My coding is as follows...........
OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
IF sy-batch IS INITIAL.
MESSAGE i001(zz) WITH 'Error opening file for upload'.
EXIT.
ELSE.
MESSAGE s001(zz) WITH 'Error opening file for upload'.
EXIT.
ENDIF.
ENDIF.
*First Uploading the data into structure
DO.
READ DATASET p_file INTO l_wa_tab. "My internal table work area
IF sy-subrc = 0.
APPEND l_wa_tab TO l_tab.
ELSE.
EXIT.
ENDIF.
ADD 1 TO count.
ENDDO.
CLOSE DATASET p_file.
Any solution for above problem.........Hi,
Check whether path ur providing to the open data set stmt is correct or not in debugging mode.
* File upload to internal table from UNIX Directory
IF NOT p_i1file IS INITIAL AND NOT p_path IS INITIAL.
CONCATENATE p_path p_i1file INTO v_file.
CONDENSE v_file.
OPEN DATASET v_file FOR INPUT IN TEXT MODE MESSAGE v_msg.
IF sy-subrc EQ 0.
WRITE: / 'INPUT FILE CONTAINS NO RECORD :'(010), v_file.
DO.
CLEAR tbl_input.
READ DATASET v_file INTO tbl_input.
IF sy-subrc NE 0.
EXIT.
ELSE.
APPEND tbl_input.
ENDIF.
ENDDO.
* Close Input File
CLOSE DATASET v_file.
ELSE.
WRITE:/'Error uploading file: '(008),v_file.
STOP.
ENDIF.
ENDIF.
It should work.check the sy-subrc value and file value in debug mode.
Thanks
Parvathi -
Reading text files in JSP pages
I want to know if it's possible to read a file and display it in an html:text area on a jsp page.
What I have right now is:
<html:file property="theFile" style="query-table-item" onclick="uploadFile(document.searchReportForm.theFile);"/> <html:reset title="Reset"/>what I wish to do, is to implement the uploadFile function, so that it can read from a text file and display it's contents onto the html:file area.
uploadFile is a javascript function that is being called from a javascript file.
I want to know if I can read the browsed file using javascript.
and if so, does someone have an idea how to do it?
Please help me out.Double post http://forum.java.sun.com/thread.jspa?threadID=647550&tstart=0
-
hi,
i have a txt file...which i am reading in my jsp page using bufferedreader class, to read txt file i have to type the absolute path of txt file as c:/myproject/xxx.txt
how can i access this txt file with relative path as xxx.txt instead of typing the absolute path c:/myproject/xxx.txt
any suggestions
Thanks2 options:
1) Put this file in one of the existing paths of the classpath, or add the path to this file to the classpath. Then use ClassLoader#getResourceAsStream() to get an inputstream of it based on the given file name.
2) Put this file in the webcontent. Then use ServletContext#getRealPath() to convert the given relative web path to an absolute filesystem path and finally use it in the constructor of FileInputStream to get an inputstream of it. -
Cannot seem to read properties file from JSP
Hi all,
In an ISA 4.0 application I want to read a properties file from a JSP to decide whether or not to execute some specific JavaScript code. I want the properties file because in it I can easily configure this externally. I put my properties file in /WEB-INF/classes.
I develop on an environment using Tomcat where this works fine. On an acceptance machine using the SAP J2EE engine however this won't work, to my surprise. Can anyone give me a suggestion on why my properties file is not read?
Here's the Java scriptlet code:
UserSessionData userSessionData = UserSessionData.getUserSessionData(session);
// theme will be something like "themes/zester":
String theme = (String) userSessionData.getAttribute(Constants.THEME_KEY);
boolean showScript = false;
int slashIndex = theme.indexOf('/');
String themeKey = null;
// get the "zester"-like part from the theme:
if(theme != null && slashIndex > -1) {
themeKey = theme.substring(slashIndex + 1);
Properties props = new Properties();
InputStream is = application.getResourceAsStream("/WEB-INF/classes/script.properties");
if(is != null) {
props.load(is);
is.close();
Enumeration keysEnum = scriptProps.propertyNames();
while (themeKey != null && keysEnum.hasMoreElements()) {
if(theme.toUpperCase().endsWith((String) keysEnum.nextElement())) {
showScript = true;
break;
showScript = false;Hi Kishor,
Thank you for taking the time!
I agree, this issue may have to do with the deployment. There is however a remark in the <a href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html">ServletContext</a> interface documentation on methods <a href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html#getResource(java.lang.String)">getResource()</a> and <a href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html#getResourceAsStream(java.lang.String)">getResourceAsStream()</a> that may also be of interest here:
"The servlet container must implement the URL handlers and URLConnection objects that are necessary to access the resource."
Is this remark of relevance to the subject, or is this thought too far fetched? Mind you, the documentation also states that "This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a .war file". It should, therefore, be possible to read a file from disk???
Cheers,
Peter-Jan Bosch -
Why the simulation is not accepting the data iam trying to give.
Why Does the "Read Waveform From File.vi" Behave Differently in the Run-time Engine?
what is the solution for this.Can you explain please.Iam also adding the vi file and the excel file I'm using.
Regards
Bharath
Attachments:
bharath.vi 12 KB
distorted ip.xls 737 KBHi Dennis,
I tried the simualtion you are given.It is giving the waveform but a portion of it only showing. Any time only 1023 samples of data is coming. That too it is coming from 17111 to 18134.I tried to change all the axis and scaling even then it is not changing. I am attaching the text files with tabs inside the elements. Can you please explain me the reason or can you send me the spread sheet file you've given for the simulation.
Thanks
Bharath.
Attachments:
bharath_2.vi 14 KB
plot.docx 29 KB -
Read xml file from jsp/servlet
Hi all,
I am a new comer to jsp and really appreciate if someone can help me on this:
I will like to use a xml file to control access to my web app instead of using a database. Let say user.xml that will contains user name and password. Questions:
1. where should I put this file? Under WEB-INF?
2. In my jsp or servlet, how do i read the xml file, i mean how to i refer to the file (depend on question 1 as where the file should be placed)?
Thank you very much.
SimHi jlsim,
you can place the xml file where you want, but remember that placing it under /WEB-INF is the most security way.
I had a similar problem and I placed the xml file under /WEB-INF directory.
To refer to it I did something like this:
String realPath=getServletContext().getRealPath("WEB-INF/xml/workspaces.xml");//obtain the real path
File f=new File(realPath);//obtain an instance of your file usable
//to create an InputStream -
How to read XLS file to sap table in backgroung
hii
i want to read file (XLS) type to sap table in background
can u help me to do that ??
thanks
Owesat EhsanHi,
Use FN Module TEXT_CONVERT_XLS_TO_SAP'
Declare Type pools: TYPE-POOLS: truxs.
Declare Data: Data i_raw TYPE truxs_t_text_data.
Declare Parameter : p_fname TYPE rlgrap-filename.
Better to Have a it_excel all fields in Char or string type. in order to avoid type mismatches.
Call FN Module and pass variables
FORM file_upload_fname USING p_fname TYPE rlgrap-filename.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = 'X'
i_tab_raw_data = i_raw
i_filename = p_fname
TABLES
i_tab_converted_data = it_excel.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
To delete header line
IF it_excel IS NOT INITIAL.
DELETE it_excel INDEX 1.
ELSE.
MESSAGE i000(0k) WITH 'No Data in Excel File'.
ENDIF.
ENDFORM. " FILE_UPLOAD_FNAME
Regards,
shiva -
How to read *.txt files with JSP?
I have to make a homepage that searches for information on a text file.
My text file is described below.
username=Hanako Sony
cpname=Sony Corporation
cpcode=500100
So, if the user inputs "username", then "Hanako Sony" should be returned. If the user inputs "cpname", then "Sony Corporation" should be returned and so on.
Can anyone help me with this? Can this be done with JSP?
Thanks,
RobTry this,
<%@ page import="java.io.*,java.util.*" %>
<%
RandomAccessFile raf = new RandomAccessFile("../webapps/test/jsp/Info.txt","r");
String qInfo = request.getParameter("qInfo");
String tInfo="";
if(qInfo != null) {
String line="";
while((line = raf.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line,"=");
if(st.hasMoreTokens()) {
if(st.nextToken().equalsIgnoreCase(qInfo))
tInfo = st.nextToken();
if(tInfo.equals("")) tInfo="Property Not found ???";
} else {
qInfo="";
%>
<form name=myform action="" method="get">
<table><tr>
<td>What do you want : </td><td><input type = text name="qInfo" value="<%=qInfo%>"></td></tr>
<tr><td>Here is the information : </td><td><input type = text name="tInfo" value="<%=tInfo%>"></td></tr>
<tr><td><input type="submit" name"sub"></td></tr>
</table>
</form>Here info.txt is your text file. Use the relative path accordingly.
Hope this helps.
Sudha -
Cannot read Property file from JSP in a Web Module Project
I have tried to read the properties file in two ways but am not able to read it because i cannot find the correct path of the properties file.
1st Method :
Properties props = new Properties();
InputStream is =
application.getResourceAsStream(
"test.properties");
if (is != null) {
props.load(is);
is.close();
Enumeration keysEnum = Props.propertyNames();
while (keysEnum.hasMoreElements()) {
out.println(keysEnum.nextElement()) ;
2nd Method :
Here "com.sap.package" is the package name and "test" is the Properties file name
ResourceBundlebundle = ResourceBundle.getBundle("com.sap.package.test");
for (Enumeration e = bundle.getKeys(); e.hasMoreElements();)
String key = (String) e.nextElement();
out.print((String) e.nextElement());
String s = bundle.getString(key);
request.getComponentSession().putValue(key, s);
I cannot read the properties file even when I keep in it the WEB-INF folder.Properties props = new Properties();
InputStream is = this.class.getClassLoader().getResourceAsStream(/test.properties);
if(is != null){
props.load(is);
Keep the test.properties in the classes folder under the web-inf folder.
Thanks,
Tim -
Encryption Type in Microsoft Excel 2013 (XLS file)
Hello,
I am creating a password protected file of format Excel 97-2003 Workbook (.xls) using Microsoft Office 2013.
I have written a java program to read password protected excel file using POI API. I am able to read .xlsx file using this API, but I am not able to read .xls file. It throw error : org.apache.poi.hssf.record.RecordFormatException: Unknown encryption
info 4
Using same java code I am able to read .xls file if I use Microsoft Office 2010 to create this file.
As per POI API documentation:
Apache POI contains support for reading few variants of encrypted office files:
XLS - RC4 Encryption
XML-based formats (XLSX, DOCX and etc) - AES and Agile Encryption
I think in Microsoft Office 2013, encryption type has been change for XLS file. So I want to know that how can I solve this issue. Also please let me know how to configure Encryption Type in Microsoft Excel 2013 Excel file.
OS is Windows 8(64-bit).
Thanks
VishalHi,
Please see the article and check if it is helpful:
https://issues.apache.org/bugzilla/show_bug.cgi?id=35897
Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
This is the forum to discuss questions and feedback for Microsoft Excel, the issue is more related to Office/Java develop, I recommend you connect the POI provide to get more help.
The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
George Zhao
TechNet Community Support
It's recommended to download and install
Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
programs. -
JSP results on excel (.xls) file
Hi all,
I want to have a link on a jsp file which would display the contents of the .jsp on an (.xls) file
I know some webpages allow this like yahoo finance does.
Can anyone please help me with this and let me know how to approach it .
Thanks in advance,
Peter....it's all about the content-type...
I'm going to bet that you haven't written an xls generator in Java... so we'll go with the next best option.... by default excel is associated with csv, so you can look at whatever mime type is assigned to csv and hopefully Excel will be used to open it.. a quick search reveals: "application/vnd.ms-excel" as the mimetype.
Maybe you are looking for
-
Blocked? Deleted? Or what
I'm sure I'm blocked because I can't see her pic, although I can on another acct that isnt.. but recently ive been able to see when shes online and when she isnt. This didnt happen earlier and shes always on skype... I don't know what to make of this
-
GMail POP3 problem: Not getting messages with sender "me"
HI guys, I have an account called [email protected] , I successfully sent mails to the same using javamail.In this messages,sender is marked as "me". Now I want to read all the messages in inbox,including the messages sent by same account itself.(mes
-
Federated Portal, Register button is Deactivated
I am trying to register Consumer Portal with Producer Portal, all the pre-requisites are met. I have created the Producer Portal Object in the Netweaver Producers--> and inputing the necessary field values. Connection tests went fine, but when I swit
-
Hola, hace unas semanas compre el IPhone 6 y siento que se hunde cuando lo tomo por la esquina inferior derecha, es normal?
-
Copying pages and states.
Is there a way to copy or import a page with different states into another fireworks document? I can't seem to find an easy way of doing this. Cutting and pasting does nothing but copy the images. Basically what I'm looking for is a way to append one