Technology Software

How to Open CSV Files in a Microsoft Excel Application Using Java Code

    • 1). Download the extraction tool at the following location:
      http://sourceforge.net/projects/datafile/files
      Extract the downloaded files into your Java directory.

    • 2). Instantiate the class and assign it to a variable. Once the class is instantiated, you can use its methods and properties:
      DataFile dataclass = DataFile.createReader("8859_1");

    • 3). Indicate the file format. The following code opens the file and tells the class that the file format is comma delimited, with the first row indicating the column header names:
      dataclass.setDataFormat(new CSVFormat());
      dataclass.containsHeader(true);

    • 4). Import the data into memory. The following syntax opens the CSV file from the hard drive:
      dataclass.open(new File("c:\\myfile.csv"));

    • 5). Read the first row of data. The code below uses the opened file variable to read the first record and store it into a variable for display:
      DataRow firstrow = dataclass.next();
      String firstrecord = firstrow.getString(0);

    • 6). Print the record to the console for display. Now the data can be used within the code or displayed to the use. The following code prints it to the screen:
      System.out.println(firstrecord);

SHARE
RELATED POSTS on "Technology"
local area network (LAN)
local area network (LAN)
How to Make Watermarks
How to Make Watermarks
How to Convert RTF to Doc
How to Convert RTF to Doc
How to Insert a Check Box in Word 2007
How to Insert a Check Box in Word 2007
How to Digital Scrapbook With Adobe Photoshop
How to Digital Scrapbook With Adobe Photoshop
RiT PatchView: Designing Your Own Personal Network With Technicians' Assisting in the Performance
RiT PatchView: Designing Your Own Personal Network With Technicians' Assisting in the Performance
Best Things About Software Development Services In India
Best Things About Software Development Services In India
Diwali Festival New Year Offer For School Management System
Diwali Festival New Year Offer For School Management System
How to Edit Pictures to Make Teeth Whiter
How to Edit Pictures to Make Teeth Whiter
3 Quick Fix Solutions to Common DVD Driver Issues
3 Quick Fix Solutions to Common DVD Driver Issues
How to Make a Java Game With NetBeans
How to Make a Java Game With NetBeans
Convert Offline EDB to PST When Exchange Server Crashed
Convert Offline EDB to PST When Exchange Server Crashed
How to Compress BMP Files
How to Compress BMP Files
How to View Two PowerPoint 2007 Presentations in Sync
How to View Two PowerPoint 2007 Presentations in Sync
How to Convert AVI to MPEG2 in Linux
How to Convert AVI to MPEG2 in Linux
xinetd
xinetd
How to Design a Corporate Enterprise Email System
How to Design a Corporate Enterprise Email System
Solving Complex Data Migration Problems With ET Tools
Solving Complex Data Migration Problems With ET Tools
Web Development Being Powered by Ajax Programming!
Web Development Being Powered by Ajax Programming!
Biztalk Server Deployment A Challenging Task For Deploying Over A Remote Account
Biztalk Server Deployment A Challenging Task For Deploying Over A Remote Account
Great Plains Small Business Financials Upgrade Overview For Consultant
Great Plains Small Business Financials Upgrade Overview For Consultant
Choosing The Right Mobile Application Development Platforms: Tips And Guidelines
Choosing The Right Mobile Application Development Platforms: Tips And Guidelines
Taking A Closer Look At SugarSynch
Taking A Closer Look At SugarSynch
Online Scheduling Software- How Online Scheduling Software Can Revolutionize Your Business
Online Scheduling Software- How Online Scheduling Software Can Revolutionize Your Business

Leave Your Reply

*