Formatting an Excel File in Java

Hi,
I have created a Excel file in Java, But i want to put each column with a specific width. How can i do this?
Help anyone?

I have this piece of code.
outputFile=new java.io.File(vVirtualDir+nomeFicheiro.toString());
java.io.FileWriter out1 = new java.io.FileWriter(outputFile);
String dados="\15\12";
out1.write("\15\12");
dados+="Column Name 1";
dados+="Column Name 2";
dados+="Column Name 3";
dados+="\15\12";
dados+="Regsiter1";
dados+="1";
dados+="1";
dados+="\15\12";
dados+="Regsiter2";
dados+="2";
dados+="2";
dados+="\15\12";
String res =new String(dados.getBytes("ISO-8859-1"));
out1.write(res);
out1.close();
This creates me the content of a Excel File. But i want to define the width of each column. How can i do that?

Similar Messages

  • 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
    Jove

    hi,
    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 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 advance

    here 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 );
    }

  • Formating an excel file by BSP Download

    I have made a BSP application which can dowload file into an excel file.But now i have a requirement in which i have to format the excel file with colour and cell width.I have to colour the column  header of the excel file with some colours like blue,red etc.
    Please suggest me how we can achieve this?
    Thanks and regards,
    Manish Kumar

    Hi Manish,
    This can be achieved using javascirpts and active x objects. Check this wiki,
    http://wiki.sdn.sap.com/wiki/display/CRM/DownloaddatafromwebuitoExcelandPPT
    Regards,
    Arun

  • 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 Me

    Thanks 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 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]);
    }

  • Reading Excel files in Java --

    Hi,
    I am trying to read an excel file from Java. It only reads the column, but I want to print the rows, which intersect with the SQL query. The following source displays only values of a column. No problem, but I would like to see the corresponding row numbers or simply number of rows. Can anyone suggest me what to do ASAP?
    Thanks,
    Gunter
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class ExcelReadTest1{
    public static void main(String[] args){
    Connection connection = null;
    try{
    //Vector vector = new Vector();
    String myString="";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection( "jdbc dbc ata-list" );
    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery( "Select caseid from [sa3$] where iSchool=2" );
    //ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );
    ResultSetMetaData rsmd = rs.getMetaData();
    int numberOfColumns = rsmd.getColumnCount();
    int row_num=1;
    while ((rs !=null) && rs.next()) {
    myString += "\n Row " + row_num++ + " ";
    for (int i = 1; i <= numberOfColumns; i++)
    //myString += "\n " + rsmd.getColumnName(i);
    myString += " : " + rs.getString(i);
    System.out.println(myString);
    if (i >1)
    System.out.print(", ");
    String columnValue = rs.getString(i);
    System.out.print(" " + columnValue);
    System.out.println("");
    st.close();
    con.close();
    } catch(Exception ex) {
    System.err.print("Exception: ");
    System.err.println(ex.getMessage());

    I took your code and reworked it to access a little database I keep of students at a small private school where my wife works. The Student table has columns "studentID", "firstname", "lastname", and "gradyear".
    Running your code for the output got the following. I cut and pasted the output after it had run through the first 4 students, so you can see what it's doing.
    Row 1 : 1
    1
    Row 1 : 1 : Audrey
    , Audrey
    Row 1 : 1 : Audrey : Budington
    , Budington
    Row 1 : 1 : Audrey : Budington : 2015
    , 2015
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2
    2
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia
    , Cecilia
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo
    , DeRigo
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    , 2015
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3
    3
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena
    , Serena
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes
    , Downes
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    , 2015
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    Row 4 : 4
    4
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    Row 4 : 4 : Dylan
    , Dylan
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    Row 4 : 4 : Dylan : Gellert
    , Gellert
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    Row 4 : 4 : Dylan : Gellert : 2015
    , 2015
    You need to figure out the flow of the thing and your println() calls and your looping. Eventually if you straighten it out you will get something like
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    Row 4 : 4 : Dylan : Gellert : 2015
    Row 5 : 5 : Benjamin : Miller : 2015
    Row 6 : 6 : Timothy : Bolan : 2014
    Row 7 : 7 : Javin : deMello-Folsom : 2014
    Row 8 : 8 : Elizabeth : Eppolito : 2014
    Row 9 : 9 : Harrison : Evans : 2014
    Row 10 : 10 : Emily : Fay : 2014
    *** etc***
    which is what you want, isn't it?

  • 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
    Lee

    That'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 Write data in Excel File using java

    Hi
    can anybody help me to write data in excel file
    using java code
    Thankx In Advance

    How much are you willing to pay for that?
    If you want it for free, http://jexcelapi.sourceforge.net/

  • 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

  • Generate Excel File using Java

    Hi,
    could any one tell me how can I create an Excel file using java. I can create the file using PrintWriter and other IO classes. But how do I insert the data in to different cells and rows.
    Any help would be greatly appreciated. Thanks in advance for your help,
    -MS

    Dear All,
    There are three ways for achiving excel operations using java including excel to xml etc.
    1. There is a very effective tool available for this operation is "jexcel". You can find it at http://www.andykhan.com/jexcelapi/index.html
    2. Jakarta site has provided a very good tool by name jakarta poifs. one can find at jakarta site.
    3. One can develop a very effective tool by combining these above tools togather.
    The operations that can be performed are read, write, convert etc for excel. The major attraction of Jexcel is excel to xml conversion.
    Regards,
    Nishant Kulkarni
    Software Engineer
    [email protected]

  • Read&write Excel file using java

    Hi everybody,
    I have an assignment about methods that read and write an excel file using java (Eclipse SDK), so if anyone know about that please post the solution as soon as possible.
    Thanks
    Sendbad

    http://onesearch.sun.com/search/onesearch/index.jsp?qt=read+write+excel&subCat=siteforumid%3Ajava31&site=dev&dftab=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums

  • Incorrect format in Excel file

    I have 2 columns in a table -
    Column C1 is a varchar2 with values like -ABC, -MNO etc i.e. every value has a '-' as the first character.
    Column C2 is a number column.
    Through a procedure, I send them to Excel file but the column C2 is displayed as text column left aligned. How do I get it as a number column in the Excel file? It happens due to the '-' in the first column.

    What is the purpose of the - character? I don't understand why Excel thinks c2 is not a number field, if it contains values like -111. A .CSV with a column of negative numbers would open up in the general number format.
    Through a procedureWhat sort of procedure? Something using SYLK? Or some other PL/SQL API?Or a Stored Java Procedure? Or UTL_FILE to write a .CSV file?
    Honestly I don't know how you expect us to solve your problem when you give us so little to go on.
    Regards, APC

  • Read an Excel file in java

    Greetings all
    I am not a java pro but have to develop a software for my company init. i need to read data from an excel file. I couldnt find proper help on the internet so thought about dropping a message here in java guru forum. i'll be obliged if somone could help me. thanks alot.

    mrityunjoy wrote:
    ejp wrote:
    you don't need to write ugly text file parsing codeParsing code isn't 'ugly' unless you don't know how to write it.I agree. However, in general people write lot of conditional statements and loops to handle different scenarios while processing text files.
    what if the delimiter itself is part of your data?The answer to that is already defined in the CSV format.Agreed, but the complications (I gave one example only) you need to tackle unless you copy or use some existing CSV file parsing code. Moreover, why to bother so much when you have a free and open source sophisticated API.
    I can think of a few reasons. At least with POI (not sure WRT to JExcel, but my guess is that this is still a valid statement), you have to build the document in memory. It is only written once all the various components have been specified in memory and then flushed to a stream. Therefore, large workbooks are problematic.
    With a CSV, I have no such issues whatsoever. I can process row-by-row with very little memory overhead. For an application, say, generating reports via Excel, this can be a nontrivial issue.
    I never said the approach: excel >> CSV >> process text is not a good option.
    Thanks,
    Mrityunjoy- Saish

  • Create an excel file from java

    I am using Jakarta's POI to create an excel file from MySql. The POI works well when a samll amount of data was written from MySql (created .xls file less than 3500KB). The problem is when a large amount of data need to be written to an excel file, java.lang.OutOfMemoryError Exception in thread "main" appears. In my project, I really need to have a large amount of data to be wriiten ton excel file. Do somebody has good solution for it?
    Thanks

    What about using some text files like csv
    (comma-separated value) file? It is plain text but
    Excel (and other spreadsheet programs) will be able to
    read it.
    But then there will be no formatting and bells and
    whistles. It was just an idea.Excel will also read HTML <TABLE>'s, with full formatting. There are some extra tags for numeric formatting, also. Just create an HTML table, and save to a file with .xls extension, e.g.:
    <TABLE>
    <TR bgcolor="#00FF7F">
    <TH>Agency ID</TH>
    <TH>POS ID</TH>
    <TH>Machine Serial</TH>
    <TH>Disk Serial</TH>
    <TH>MAC ID</TH>
    <TH>System Manufacturer</TH>
    <TH>Machine Type</TH>
    <TH>BIOS Manufacturer</TH>
    <TH>BIOS Version</TH>
    <TH>BIOS Date</TH>
    </TR>
    <TR bgcolor="#9ACD32">
    <TD>1000</TD>
    <TD>1069</TD>
    <TD STYLE='vnd.ms-excel.numberformat:@'>US215199248</TD>
    <TD STYLE='vnd.ms-excel.numberformat:@'>5C5AE88F3</TD>
    <TD STYLE='vnd.ms-excel.numberformat:@'>000423155334</TD>
    <TD>Hewlett-Packard</TD>
    <TD>Desktop</TD>
    <TD>American Megatrends Inc.</TD>
    <TD>JA.01.03US</TD>
    <TD>07/19/2001</TD>
    </TR>
    </TABLE>

Maybe you are looking for

  • How to play .wav file from URL in web browser embed

    Hi; I want to play a .wav sound file in embed default media player in IE. Sound file is on some HTTP location. I am unable to sound it in that player. Following is the code. URL url = new URL("http://www.concidel.com/upload/myfile.wav");         URLC

  • IPod Nano would not connect to Windows or Format. *SOLVED*

    Ok, first post and I am just posting to thank those who have posted some different things to try, thanks to you guys, I have a working iPod Nano. Here is what I tried... The Problem iTunes would not see my nano and could not format the nano during in

  • Trying to Understand Color Management

    The title should have read, "Trying to Understand Color Management: ProPhoto RGB vs, Adobe RGB (1998) my monitor, a printer and everything in between." Actually I could not come up with a title short enough to describe my question and even this one i

  • JDeveloper BPEL/ESB Designer

    I'm going spare trying to set up a version of JDeveloper with the BPEL / ESB plugin. I have found and tried to follow Oracle documentation fo the BPEL Process Manager which claims that JDeveloper with BPEL Designer is installed with BPEL Process Mana

  • Safari crashes or will not complete loading - just updated to 3.2.1

    Hey there, I hope this post gives enough information for a quick answer. I just did a software update to 3.2.1. Rebooted after the install and since then I haven't been able to use Safari fully - initial start wouldn't load my tabs/windows from previ