Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

java code to convet to CSV

Ads

 
 

Share on Google+Share on Google+

dooper
java code to convet to CSV
0 Answer(s)      5 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;
}
Ads
View Answers
Ads









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
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
storing csv into oracle database
storing csv into oracle database  i want jsp code for storing csv file into oracle database
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
JAVA code For
JAVA code For   JAVA code For "Traffic signals Identification for vehicles
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><
java code
java code  what is the code to turn off my pc through java program
JAVA CODE
JAVA CODE  JAVA SOURCE CODE TO BLOCK A PARTICULAR WEB SITES(SOCIAL WEB SITE
java code
java code  write a java code to convert hindi to english using arrays
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
java code
java code  hi any one please tell me the java code to access any link i mean which method of which class is used to open any link in java program
java code
java code  need java code for chart or graph which compare the performance of aprior algorithm and coherent rule algorithm.plz any one help me out
java code
java code  write a java code for finding a string in partiular position in a delimited text file and replace the word with the values given by user and write the file in new location
java code
java code  sir how to merge the cells in excel using java code please help me and also how to make the text placed in the cell to be center
java code
java code  sir how to merge the cells in excel using java code please help me and also how to make the text placed in the cell to be center
java code
java code  develop a banking system in java
java code
java code  I need the java code that would output the following: HARDWARE ITEMS CODE DESCRIPTION UNIT PRICE K16 Wood screws,brass,20mm $7.75 D24 Wood glue,clear,1 liter $5.50 M93
Java code
Java code   Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes
java code
java code  how to extract html tags using java