JXL Excel file Java sample code description

Source: Internet
Author: User

Remember to download and import the Jxl.jar package, free points: http://download.csdn.net/detail/u010011052/7561041

Package Test;import java.io.*;import jxl.*;import jxl.format.colour;import jxl.write.*;p ublic class JXLTest {private Static Writableworkbook book;private static Writablesheet sheet;p rivate static writablefont normalfont;private static Wr Itablefont difffont;private static Writablecellformat normalformat;private static Writablecellformat diffFormat;/** * Java creates an Excel simple Demo sample */public static void Main (String args[]) {createexcel ();} public static void Createexcel () {try {String Filenameandpath = "E:\\differentdata\\java Create an Excel file Demo sample. xls"; Workbook.createworkbook (Filenameandpath);//Generate a worksheet named "first page" with the number of 0 indicating that this is the first page sheet = book.createsheet ("First page", 0);// Set the font to Arial, 11th, not bold, color red Normalfont = new Writablefont (Writablefont.createfont ("Arial"), one, writablefont.no_bold);// Set the font to Arial, 11th, not bold, color red Difffont = new Writablefont (Writablefont.createfont ("Song Body"), one, writablefont.no_bold); Difffont.setcolour (colour.red); Normalformat = new Writablecellformat (Normalfont); Normalformat.setalignment ( Jxl.format.AliGnment. CENTRE); Normalformat.setverticalalignment (Jxl.format.VerticalAlignment.CENTRE);d Iffformat = new Writablecellformat (Difffont);d iffformat.setalignment (Jxl.format.Alignment.CENTRE); Diffformat.setverticalalignment (Jxl.format.VerticalAlignment.CENTRE); Label Labela = new label (0, 0, "first column header", Normalformat); Label Labelb = new label (1, 0, "second column header", Normalformat); Label LABELC = new label (2, 0, "third column header", Normalformat); Label Labeld = new label (3, 0, "fourth column header", Normalformat), for (int i=1; i<=10; i++) {Label lab1 = new label (0,i, "+i+" Row 1th column) ; Label LAB2 = new label (2,i, "2nd column" of "+i+"); Label LAB3 = new label (3,i, "3rd column" of "+i+", Diffformat); Label LAB4 = new label (4,i, "4th column" of "+i+"); Sheet.addcell (LAB1); Sheet.addcell (LAB2); Sheet.addcell (LAB3); Sheet.addcell (LAB4);} Add the defined cells to the worksheet Sheet.addcell (Labela); Sheet.addcell (Labelb); Sheet.addcell (LABELC); Sheet.addcell (Labeld); Book.write (); Book.close (); System.out.println ("Create file succeeded!");} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} FinallY{}}} 


Read CSV file

File CSV = new file ("e:\\ four-dimensional poi.csv of Jiangsu province"); CSV file BufferedReader br = new BufferedReader (new FileReader (CSV))//for (int num = 1; num<=rowmaxnum; num++) {String Li Netext = "";//read until the last line int i=0;while ((Linetext = Br.readline ()) = null && i<=200) {if (i>0) {String arr[] = Linetext.split (","); String pnname = arr[0]; String point_x = arr[1]; String point_y = arr[2]; String poiid = arr[3];finddifferent (PNNAME,POINT_X,POINT_Y,POIID);} i++;} Br.close ();


Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

JXL Excel file Java sample code description

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.