How to print Excel file in java?
Hi, all
I had written a program to generate a Report with Excel in java using the jexcelapi_2_5_7 . But I don't know how to print it in java program. It seems that java print Service don�t support Excel flavor. How should I do? It will be a great appreciate for me if anyone could help me.
Regards
David
Hi ,
i m asking if you got a solution for your problem ;
i need solution to the same problem
thx in advance
Similar Messages
-
How to print PDF files using java print API
Hi,
I was goign throw lot of discusion and reading lot of forums related to print pdf files using java api. but nothing seems to be working for me. Can any one tell me how to print pdf files using java api.
Thanks in advanceMike,
Can't seem to get hold of the example described in your reply below. If you could let us have the URL to get then it would be great.
My GUI application creates a pdf document which I need to print. I want to achieve this using the standard Java class PrinterJob (no 3rd party APIs I'm afraid, commercial restraints etc ..). I had a stab at it using the following code. When executed I get the pretty printer dialog then when I click ok to print, nothing happens!
boolean showPrintDialog=true;
PrinterJob printJob = PrinterJob.getPrinterJob ();
printJob.setJobName ("Contract.pdf");
try {
if (showPrintDialog) {
if (printJob.printDialog()) {
printJob.print();
else
printJob.print ();
} catch (Exception PrintException) {
PrintException.printStackTrace();
Thank you and a happy new year.
Cheers,
Chris -
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 );
} -
How to print PDF file from java application?
Hi,
I have a java application that needs to print an PDF files. Could any one provide me links to tutorial/sample codes for doing this?http://onesearch.sun.com/search/onesearch/index.jsp?qt=print+pdf+files&subCat=&site=dev&qp=&chooseCat=javaall&col=developer-forums
-
How do Print TXT file in JAVA...?
Dear sir,
i have a program for printing txt file.... i tried below program..
1. This code executed without exception... but its not printing.... when i saw print buffer, file is add but not printing
2. Please help me out.... or give me some clue.... where i doing wrong....?
Note:- am trying remote printing
try {
FileInputStream fin = new FileInputStream(".\\file\\down.txt");
// set up attributes set
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1)); // number of copies
// find the priner service
PrintService pss = PrintServiceLookup.lookupDefaultPrintService();
if (pss == null)
throw new RuntimeException("No printer services available.");
PrintService ps = pss;
System.out.println("Printing to " + ps);
// create print job
DocPrintJob job = ps.createPrintJob();
// print data
Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
// print it
job.print(doc, pras);
// close file
fin.close();
} catch (IOException ie) {
ie.printStackTrace();
} catch (PrintException pe) {
pe.printStackTrace();
}Thank you
boss134Hi ,
i m asking if you got a solution for your problem ;
i need solution to the same problem
thx in advance -
How to compare two excel files in java ?
how do i compare two excel files in java.?
I have two excel files stored on my computer in d: drive.
Ex:
D:\\file a
D:\\file b
How to compare the contents of these two files and print " files are equal " or "files not equal "Javamastermahe wrote:
I mean i want to print on the console "files are equal " or any message like " both the files match "If this is your requirement, this program satisfies it...
import java.util.Random;
public class SuperExcelTester {
public static void main(String[] args) {
Random rnd = new Random();
String[] messages = {
"files are equal",
"files are not equal",
"unexpected error"
int index = rnd.nextInt(messages.length);
System.out.println(messages[index]);
} -
How to save html as Excel file im java
Hi to all
How can i save html file as Excel file in Java
If any solutions plz help MeThanks for ur reply
Source URL is::http://www.sttpc.com/reseller/price.htm
Target is to save table data into Excel Sheet.
Upto saving that file as Excel file its working (using I/O).
When iam trying to read excel sheet data then iam getting OLE Exception.
plz suggest me other Alternate solutions to overcome this problem.
I tried htmlparser from sourceforge.net i got partial ouput.But i want dynamic solution.
Thanks. -
How do I produce an excel file using java code
How do i produce an excel file using java code.
If it is possible would ne one have ne source code as an example.
I have tried looking up information on outputing the information to a *.csv file but unfortunality i have had no luck in finding any information. To be exact ne source code.
Thanks
LeeThat's what I use and I'd be the first to admit that it's very messy. But it works. Go use Google and see what else you can find.
-
How to compare two files in java & uncommon text should print in text file.
Hi,
Can any one help me to write Core java program for this.
How to compare two files in java & uncommon text should print in other text file.
thanks
SamHi All,
i m comparing two HTML file.. thats why i am getting problem..
import java.io.BufferedReader;
import java.io.FileReader;
public class textmatch{
public static void main(String[] argv)
throws Exception{
BufferedReader fh =new BufferedReader(new FileReader("internal.html"),1024);
BufferedReader sh = new BufferedReader(new FileReader("external.html"),1024);
String s;
String y;
while ((s=fh.readLine())!=null)
if ( s.equals(y=sh.readLine()) ){
System.out.println(s + " " + y); //REMOVE THIS PRINTLN STATEMENT IF YOU JUST WANT TO SHOW THE SIMILARITIES
sh.close();
fh.close(); }
thanks
Sam -
How to compare two files in Java & uncommon text should print in Diff text
Hi All,
can any one help me to write a java program..
How to compare two files in Java & uncommon text should print in Diff text file..
Thanks
SamHi All,
i m comparing two HTML file.. thats why i am getting problem..
import java.io.BufferedReader;
import java.io.FileReader;
public class textmatch{
public static void main(String[] argv)
throws Exception{
BufferedReader fh =new BufferedReader(new FileReader("internal.html"),1024);
BufferedReader sh = new BufferedReader(new FileReader("external.html"),1024);
String s;
String y;
while ((s=fh.readLine())!=null)
if ( s.equals(y=sh.readLine()) ){
System.out.println(s + " " + y); //REMOVE THIS PRINTLN STATEMENT IF YOU JUST WANT TO SHOW THE SIMILARITIES
sh.close();
fh.close(); }
thanks
Sam -
How to connect XLSX(MS Office 2007 Excel file) in java
i successfully connected ms office 2003 *.xls* file with the help of JXL library
can any one tell me how can i connect XLSX (MS Office 2007 Excel file) in java.http://www.smartxls.com/indexj.htm is commercial library (not free) also a poor documentation
can you give me a sample code of reading and writing xlsx file
http://poi.apache.org/spreadsheet/index.html free library.
but sample code are difficult to understand .
if you have a good and simple example code please give me OR any other reffrences -
How to format a excel file use java.
hi,
everyone, i meet a problem.i want to write a excel file use java.i can use .csv input the date to excel.but i want to know how to format it.
thanks
Jovehi,
everyone, i meet a problem.i want to write a excel
el file use java.i can use .csv input the date to
excel.but i want to know how to format it.
thanks
JoveIf I understand your question correctly you need to know the format of a .csv file for use in an Excel spreadsheet. A .csv file is a comma-delimited file so all that you need to do is write your data elements to the file with commas in between them. Having done something similar in the past, let me warn you that when Excel is reading your file, it uses some characters other than commas as field delimiters. for example, / : and ; are treated as commas. To defeat this, you will need to surround fields containing those characters in double quotes.
Hope that helps
Mark -
How to Write data in Excel File using java
Hi
can anybody help me to write data in excel file
using java code
Thankx In AdvanceHow much are you willing to pay for that?
If you want it for free, http://jexcelapi.sourceforge.net/ -
How to print *.PRN file without print Dialog from Java
hi friends
I need to print *.PRN file from java code.*
I need to print directely without open printer dialog box when i select .PRN file then it should able to direct print to default printer.
Here is the Dos command to directely print the PRN file
COPY C:\\PrintFile.prn /B \\java103\\HPLaserJ
(source: http://filext.com/faq/print_from_prn_file.php)
i try to run that dos command through Process p = Runtime.getRuntime().exec("COPY C:\\PrintFile.prn /B \\java103\\HPLaserJ");
But is show that
Here is the LOG of ERROR
\\java103\HP LaserJet M1120 MFP
java.io.IOException: Cannot run program "COPY": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at Print2Printer.GetDefaultPrinter.main(GetDefaultPrinter.java:17)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
Here is the Source
import java.io.IOException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
public class GetDefaultPrinter {
public static void main(String args[]){
PrintService printer = PrintServiceLookup.lookupDefaultPrintService();
System.out.println(printer.getName());
try {
Process p = Runtime.getRuntime().exec("COPY C:\\PrintFile.prn /B \\java103\\HPLaserJ");
System.out.println(p);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();you need to specify which program you want to execute in Runtime.getRuntime().exec(). So try this one
try {
Process p = Runtime.getRuntime().exec("cmd.exe COPY C:\\PrintFile.prn /B \\java103\\HPLaserJ");
System.out.println(p);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} -
How to print the file name in sap
Hi All,
I have requirment like,
there is a folder in my local system, inside that folder there are 10 Excel file like file1.xls,file2.xls..............file10.xls
how to print the file name of all these file in SAp like
file1.xls
file2.xls
file3.xls
file4.xls
file10.xls
Appropriate points will be rewarded.
Thanks in Advance
Arun kumarHi,
Still you are facing any problem with this code expalin the problem with details , otherwise close this thread.
Use Method <b>cl_gui_frontend_services=>directory_list_files</b> to read file names for a given directory
after reading the files then Use FM : <b>RSPO_SX_OUTPUT_TEXTDATA</b> to create spool from internal table data and print the data.
<b>sample code :</b>
data: desktop_dir type string.
data: ifiles type table of string.
data: xfiles type string.
data: count type i.
data: filepath type string.
call method cl_gui_frontend_services=>get_desktop_directory
changing
desktop_directory = desktop_dir .
call method cl_gui_cfw=>flush.
call method cl_gui_frontend_services=>directory_list_files
exporting
directory = desktop_dir
* filter = '*.xls'
files_only = 'X'
* DIRECTORIES_ONLY =
changing
file_table = ifiles
count = count.
DATA : x_name LIKE tsp03d-name,
x_dest LIKE tsp03d-padest VALUE 'LOCL',
x_rows LIKE sxpcklsti1-body_num VALUE 0,
x_startrow LIKE sxpcklsti1-body_start VALUE 1,
x_pages LIKE rspotype-pages VALUE 1,
x_pages_1 TYPE p DECIMALS 2,
x_rqtitle LIKE sxpcklsti1-obj_descr,
x_rqcopies TYPE i VALUE 1,
x_rqowner LIKE trdyse01cm-username,
x_immediate LIKE pri_params-primm VALUE ' ',
x_rqid LIKE tsp01-rqident,
i_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
x_pages = 1.
x_rqowner = sy-uname.
x_dest = 'LOCL'.
x_startrow = 1.
x_rqcopies = 1.
x_immediate = 'X' .
CALL FUNCTION 'RSPO_SX_OUTPUT_TEXTDATA'
EXPORTING
* name = x_name
dest = x_dest
rows = x_rows
startrow = x_startrow
pages = x_pages
rqtitle = x_rqtitle
rqcopies = x_rqcopies
rqowner = x_rqowner
immediately = x_immediate
IMPORTING
rqid = x_rqid
TABLES
text_data = i_contents
EXCEPTIONS
name_missing = 1
name_twice = 2
not_found = 3
illegal_layout = 4
internal_error = 5
size_mismatch = 6
OTHERS = 7.
IF sy-subrc <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regards
Appana
*Reward Points for helpful answers
Message was edited by: L Appana
Maybe you are looking for
-
Get kernel panic when I burn DVDs
when I burn several DVDs using the internal DVD burner on my 1.25 Ghz G4 running OS X 10.4.11, I am getting a kernel panic that tells me to reboot my computer. I'm using Toast Titanium 8 to burn with. Any ideas how to prevent this? Here's the details
-
Hi, I have problem with unstable starting up of win7 64-bit with my Lenovo T520. Usually it occurs every day and than 2nd or 3rd restart is successful. Typically win7 is frozen after startup, sometimes "blues screen" appears but with very random BSOD
-
One step purchase order approval - Trigger only in certain cases.
Hi, I want to trigger the one step workflow approval for Purchase Orders only in ceraitn cases. When the PO is created from a shopping cart it has to be automatically approved. In other cases the workflow has to be triggerred. I tried setting the
-
Movies fail to load and playback in web browsers
I can't seem to load and playback what appear to be QT movies in Safari, Chrome , or Firefox. A black window sits there and all I get is a spinning blue circle in the middle of the screen for a long time. I have a 2.66 Ghz intel imac with 2 gigs of R
-
Premiere CC hangs on large projects
Hey! Adobe Premiere CC seems to hangs on my projects that have a lot of video footage in them. I do not have this problem in CS6, only in CC. In the video below CSCooper2000 shows the exact issue I'm having. http://www.youtube.com/watch?v=zHzdX9cho