Summary of the top500 statistical process (Perl, Shell, Java) [3-Java]

Source: Internet
Author: User
Tags perl script
Iii. Java-related

The reason why the shell program calls the Java program is: the Excel file generated by the Perl script, where the entry URL cannot be decoded to recognize Chinese characters (related to Linux coding, you cannot change the system encoding. Therefore, you must use a Java program to process the Excel files generated by Perl ). For example
Save to the new Excel file.

For the basic operations on reading and writing excel in Java, refer to the most comprehensive explanation of exporting excel in jxl.

Java can read and write Excel files in two ways: org. Apache. Poi and jxl (to import a jar package: jxl. Jar ). I started to use the poi method, but this method handles the total error of the original Excel file:

Java. Lang. runtimeexception: Unexpected record type (Org. Apache. Poi. hssf. Record. hyperlinkrecord)
At org. Apache. Poi. hssf. Record. Aggregates. rowrecordsaggregate. <init> (rowrecordsaggregate. Java: 98)
At org. Apache. Poi. hssf. model. Sheet. <init> (sheet. Java: 203)
At org. Apache. Poi. hssf. model. Sheet. createsheet (sheet. Java: 158)
At org. Apache. Poi. hssf. usermodel. hssfworkbook. <init> (hssfworkbook. Java: 287)
At org. Apache. Poi. hssf. usermodel. hssfworkbook. <init> (hssfworkbook. Java: 201)
At org. Apache. Poi. hssf. usermodel. hssfworkbook. <init> (hssfworkbook. Java: 317)
At org. Apache. Poi. hssf. usermodel. hssfworkbook. <init> (hssfworkbook. Java: 298)
At com. Hudong. Test. testpoi. Read (testpoi. Java: 105)
At com. Hudong. Test. testpoi. Read (testpoi. Java: 79)
At com. Hudong. Test. testpoi. Main (testpoi. Java: 36)

To solve this problem, open the Excel file and click Save when you close it twice. The problem is solved. However, no one asks you to click excel on the server twice each time. Therefore, you can use jxl to process the Excel files generated by Perl.


1. utf8 Decoding of recognizable Chinese characters (Java ):

String temp = http://www.hudong.com/wiki/%E5%8D%95%E6%9B%B2%E5%BE%AA%E7%8E%AF%E7%97%87temp = URLDecoder.decode(temp,"utf-8");

The encoding method is urlencoder. encode ();


2. Read and Write Excel files in Java: (Resources uploaded, downloadable, in my resources)

Decodeexceljxl. Java

Use ARGs [] to directly obtain the parameters passed by the shell script.

Public static void main (string [] ARGs) throws biffexception, ioexception, rowsexceededexception, writeexception {// obtain the Excel table to be processed if (ARGs! = NULL & args. Length = 1) {filepath = ARGs [0];} rewritewithnew (filepath );}

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.