JXL Generate tables (merge cells, fonts, styles ...) )

Source: Internet
Author: User
	public static String TestEx () {//A, the computed path simpledateformat SDF = new SimpleDateFormat ("/yyyy-mm-dd/");
		String Datepath = Sdf.format (New Date ());
		Datepath = "China Petroleum Western Pipeline Transmission Volume transfer Electronic document" + Datepath;

		String uuidfilename = Uuid.randomuuid (). toString ();

		Create folder File Dir = new file (Globals.fielimportpath + Datepath);
		if (!dir.exists ()) {dir.mkdirs ();
				String Path = Globals.fielimportpath + Datepath + uuidfilename + "."

		+ "XLS";

			try {writableworkbook WWB = Workbook.createworkbook (new File (path));
			Writablesheet sheet1= wwb.createsheet ("Top Five", 0);
			Writablesheet Sheet2 = Wwb.createsheet ("Post two", 1);
			
			Writablesheet Sheet3 = Wwb.createsheet ("Post three", 2); Sheet1.setcolumnview (0, 30); Sets the width of the column sheet1.setcolumnview (1, 30); Sets the width of the column Sheet1.setcolumnview (2, 30); Sets the width of the column Sheet1.setcolumnview (3, 30); Sets the width of the column Sheet1.setcolumnview (4, 30); Sets the width of the column Sheet1.setcolumnview (5, 30); Sets the width of the column sheet1.setrowview (0, 1000);
Set the height of a row			Sheet1.setrowview (1, 500); Set the height of the row/** * Define cell style * * Writablefont wf_title = new Writablefont (writablefont.arial, WRITABL Efont.bold, False, Underlinestyle.no_underline, Jxl.format.Colour.RED); Define formatting font underline italic bold color Writablefont wf_head = new Writablefont (Writablefont.arial, Writablefont.bold, False, Underlinestyle.no_underline, Jxl.format.Colour.GREEN); Define formatting font underline italic bold color Writablefont wf_table = new Writablefont (writablefont.arial, 8, Writablefont.bold, False, Underlinestyle.no_underline, Jxl.format.Colour.BLACK); Define formatting font underline italic bold color Writablecellformat wcf_title = new Writablecellformat (wf_title); Cell definition Wcf_title.setbackground (Jxl.format.Colour.BLACK); Sets the background color of the cell wcf_title.setalignment (Jxl.format.Alignment.CENTRE); 
			Set Alignment Writablecellformat Wcf_head = new Writablecellformat (wf_head);
			Wcf_head.setbackground (Jxl.format.Colour.BLACK); Wcf_head.setalignment (Jxl.format.Alignment.CENtre); 
			Writablecellformat wcf_table = new Writablecellformat (wf_table); 
			Wcf_table.setbackground (Jxl.format.Colour.BLACK); 
			
			Wcf_table.setalignment (Jxl.format.Alignment.CENTRE); /** * Use style cells//1. Add a Label object three parameters meaning: "column, Row, value" Sheet1.addcell (new Label (0, 0, "title", Wcf_title));
			Normal cell Sheet1.addcell with defined format (new Label (0, 1, "Table Head 1", wcf_head));
			Sheet1.addcell (New Label (1, 1, "Table Head 2", Wcf_head));
			Sheet1.addcell (New Label (2, 1, "Table Head 3", Wcf_head));
			Sheet1.addcell (New Label (3, 1, "Table Head 4", wcf_head));
			Sheet1.addcell (New Label (4, 1, "Table Head 5", Wcf_head));
			
			Sheet1.addcell (New Label (5, 1, "Table Head 6", Wcf_head)); Sheet1.mergecells (0, 0, 5, 0);
			Merge cells//write to Exel worksheet wwb.write ();
			

		Closes the Excel Workbook object Wwb.close ();
			catch (Exception e) {e.printstacktrace ();
		return "0";
	return path;
		public static void Main (string[] args) {Utilio uio=new utilio ();
	System.out.println (Uio.testex ()); }



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.