PDF Schema Database data export

Source: Internet
Author: User

/**
*
* Export
* @throws FileNotFoundException
*/
Public String Excel () throws filenotfoundexception{
Put it under Tomcat.
String filename= "User Management";
String pathname=servletactioncontext.getrequest (). GetSession (). Getservletcontext (). Getrealpath ("") + "\\export\\" +filename+ ". xls";

4.1 Defining a table header
String tablename= "T_user";
String tablecname = selectdataservice.getstring ("Select Comments from user_tab_comments WHERE table_name = '" +tablename+ "‘");



4.2 Get the Chinese comment for the table
List<map> list=selectdataservice.queryforlist ("Select t.column_name,t.comments from User_col_comments t where table_name = ' "+tablename+" ' ");

4.2 Creating a list
List<string> columns=new arraylist<string> ();
Map<string, string> colmap=new treemap<string, string> ();
for (Map map:list) {

Take the comments out of the database and put them in the columns.
Columns.Add (Map.get ("COMMENTS"). toString ());
Put the Chinese note of the repository into the map collection
Colmap.put (Map.get ("COMMENTS"). ToString (), Map.get ("column_name"). ToString ());

}


1 Creating Hssfworkbook
Hssfworkbook hssfwork=new Hssfworkbook ();

2 Creating sheet
Hssfsheet sheet = hssfwork.createsheet (tablecname);

3 Creating a title row (row)
Hssfrow row = sheet.createrow (0);

4 Creating cells
for (int i = 0; i < columns.size (); i++) {
Create a single cell
Hssfcell Createcell = Row.createcell (i);
Put the value taken in the cell.
Createcell.setcellvalue (List.get (i). Get ("COMMENTS"). toString ());
}

5 Remove all data from the database
List<map> datalist=selectdataservice.queryforlist ("select * from" +tablename);

6 Convenience of all data
The I loop is a loop, and the J loop is a loop that loops through each value in a single piece of data.
for (int i = 0; i < datalist.size (); i++) {

Get a row of data
Map Cols=datalist.get (i);

Create a header row
Hssfrow RowData = Sheet.createrow (i+1);

System.out.println ("cols>>>" +cols);

A J loop is a loop that loops through each value in a single piece of data
for (int j = 0; J < Cols.size (); j + +) {

Put it in every cell.
String Fangyuange = Columns.get (j);

Go to English writing section
String ing = colmap.get (fangyuange);

Put in a list of
Object value = cols.get (ing);

Create cells (through rows) into cells
Hssfcell cell = Rowdata.createcell (j);
Cell.setcellvalue (Value.tostring ());

}
}


FileOutputStream fos=new FileOutputStream (pathName);

Put in the path
try {
Hssfwork.write (FOS);
Servletactioncontext.getresponse (). Getwriter (). Write ("OK");
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}finally{

try {
Fos.close ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}

}
return null;


}

PDF Schema Database data export

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.