dooper
java code to convet to CSV
0 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners
public static StringBuffer convert(JTable table) {
    StringBuffer sbf = new StringBuffer();
    // Check to ensure we have selected only a contiguous block of cells
    int numcols = table.getColumnCount();
    int numrows = table.getSelectedRowCount();
    int[] rowsselected = table.getSelectedRows();

    if (numrows <= 0) {
        JOptionPane.showMessageDialog(null, "Invalid Copy Selection. Please select atleast one Row.", "Error",
                                      JOptionPane.ERROR_MESSAGE);
        return null;
    }
    for (int i = 0; i < numcols; i++) {
        sbf.append(table.getColumnName(i));
        if (i < numcols - 1) {
            sbf.append(",");
        }
    }
    sbf.append("\n");

    for (int i = 0; i < numrows; i++) {
        for (int j = 0; j < numcols; j++) {
            Object obj = table.getValueAt(rowsselected[i], j);
            if (obj instanceof String) {
                sbf.append("\"");
                sbf.append(obj);
                sbf.append("\"");
            } else if (obj instanceof XDouble) {
                sbf.append("\"");
                sbf.append(table.getValueAt(rowsselected[i], j));
                sbf.append("\"");
            } else if (obj instanceof java.sql.Timestamp) {
                XDate wdt = new XDate((java.sql.Timestamp)
                                      obj);
                sbf.append(wdt);
            } else {
                sbf.append(table.getValueAt(rowsselected[i], j));
            }
            if (j < numcols - 1) {
                sbf.append(",");
            }
        }
        sbf.append("\n");
    }
    return sbf;
}
Advertisement
View Answers









Related Tutorials/Questions & Answers:
java code to convet to CSV
java code to convet to CSV  public static StringBuffer convert(JTable table) { StringBuffer sbf = new StringBuffer(); // Check to ensure we have selected only a contiguous block of cells int numcols
How to convet reader to double? - Java Beginners
How to convet reader to double?  I have this set of coding which read the input from the com1 port. I wan to ask how to convert the input (the reader) into Double so that the input can perform arithmetic operation
Advertisements
sir, how to convert excel file to csv file using java? please send me sample code.
sir, how to convert excel file to csv file using java? please send me sample code.  please send me sample code for converting excel file into csv file uisng java
How to write into CSV file in Java
How to write into CSV file in Java  How to write into CSV file in Java   Hi, To create Comma separated value(CSV) file is very simple... Object to PrintWriter instance. How to create File to CSV in Java
java, upload csv file - Development process
java, upload csv file  hi, i have a csv file having 29 colums, i want to upload that csv file to database. i need the code,, can u please send me the code.. thanks..  Hi Friend, Please visit the following
PHP code for csv file upload into mysql
PHP code for csv file upload into mysql  I want to upload a file from my pc to mysql server using upload option. while i m selecting the csv file it ll be upload the mysql database. can u send me the coding? i have tried
Convert CSV to excel File - Java Beginners
Convert CSV to excel File  Sir, i have CSV file as input. I need to convert that CSV file to excel file and format. Currently i am using HSSF POI api to format the excel file. Here i am unable to read the data from the CSV
Java Write To File CSV
Java Write To File CSV In this tutorial you will learn how to write to file csv CSV (Comma Separated Value) files stores the value in rows and columns that is in a tabular form. In java to create a csv file is simple, you would require
convert .txt file in .csv format - Java Beginners
convert .txt file in .csv format  Dear all, I hope you are doing good. I am looking to convert .txt file in .csv format. The contents might have... want export these contents to a .csv file. I am aware that I need to use
Java Read CSV file
Java Read CSV file In this tutorial, you will learn how to read csv file. CSV... to break the line using ",". The delimiter for a CSV file is a comma.... Here is a csv file: Example import java.io.*; import java.util.*; public
retrieve multiple columns values from multiple csv files in java
retrieve multiple columns values from multiple csv files in java  Suppose there is folder in C:\fileupload which contains these two csv files... be specific in telling me through java only Any help will be much appreciated
storing csv into oracle database
storing csv into oracle database  i want jsp code for storing csv file into oracle database
importing CSV data into Database in java when the no of columns are known using javacsv
importing CSV data into Database in java when the no of columns are known using javacsv   I have imported CSV data into postgres Database in java... that if the no of columns in the csv are not known then also i should be able to import
how to sort multiple key columns in CSV file - Java Beginners
how to sort multiple key columns in CSV file  Hi Any one can assist how to sort the multiple key columns in CSV file? Any example will be appreciated. Thanks
CSV tables
CSV tables  hello, What are CSV tables?   hii, CSV Tables cannot be indexed.CSV Tables are the special tables, data for which is saved into comma-separated values files
Err while reading CSV file using POI - Java Beginners
Err while reading CSV file using POI  Hi, When i am trying to read a CSV file using POI Dile system, the below error is coming up... know, why this is coming up. Is there any other way to read the CSV file. Thanks
HTML Form data into .CSV?
HTML Form data into .CSV?  how to store data from html form to csvfile in java
.csv file to databse
.csv file to databse  I have an 1 .csv file.. its having the url values like http://maps.google.com/?q=425+Bingeman+Centre+Drive%2c+chrompet%2c+ON%2c+600+006... q is request parameter .425 Bingeman Centre Drive is address
csv file download
csv file download  Hello Every one, when user clicks download button I want to retrieve data from mysql database table in csv format using java.if you know please send code. Thanks in Advance   Please visit
Exporting data from mysql to csv file
Exporting data from mysql to csv file  Hi friends.... I want to export the data from mysql to csv file... i am having 30 columns in my database.. Eg- text1,text2,text3,....,upto text30... i want to export this data in csv file
How create csv format in jsf ?
How create csv format in jsf ?  Dear Friends , Good morning to all of you? I have a problem to create .CSV format in jsf. Actully I have... for database connectivity . and In handler I have write the code to genterate
how to parse a csv file using standard libraries?
how to parse a csv file using standard libraries?  hie i am a beginner in java i want to parse a csv file using any standard libraries i want to know how the libraries are imported and used in eclipse thanks in advance
JAVA code For
JAVA code For   JAVA code For "Traffic signals Identification for vehicles
Export data into CSV File using Servlet
Export data into CSV File using Servlet  ... to Export data into  CSV file using Servlet. We have created  file "JdbcCsvFile.java" to export data from this .java file.. Brief
phpmyadmin - upload csv files - SQL
phpmyadmin - upload csv files  i have database in phpmyadmin. i have upload one time in csv file. i need to another csv file in upload same table. i will try to do this but result is failed. (table rows and csv rows are same
Upload CSV File into Columns of sql table using servlets and jsp
Upload CSV File into Columns of sql table using servlets and jsp  Hello sir, plz give me the code to upload csv file data into respective columns of table
java code
java code  Hai,I need to download the data file from database with csv format using java/servlet.I would like to download the csv file when user... and then download that file using Servlet. 1)page.jsp: <%@ page language="java
java code
java code  Hai,I need to download the data file from database with csv format using java/servlet.I would like to download the csv file when user.... 1)page.jsp <%@ page language="java" %> <Html> <HEAD><
export value in csv from jsp
export value in csv from jsp  Hi! i have creted a html form using javascript. i hv taken the array values in jsp. nw i want to pass these array values from jsp to csv file. so please help me how to send
java code
java code  write a java code to convert hindi to english using arrays
JAVA CODE
JAVA CODE  JAVA SOURCE CODE TO BLOCK A PARTICULAR WEB SITES(SOCIAL WEB SITE