BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  37 Posts :: 3 Stories :: 24 Comments :: 0 Trackbacks

Recently,we are maintaining a project and there is a bug "unreadable content in *.xls" when we export the excel report using the POI.For several days,we are unable to find the real reason.though from the beginning,we thought that It was the format,cell style,link problem.finally,we find that It is due to the Hyperlink problem.Of course ,there maybe other reasons which can cause this error.

The example below comes from the POI website and I make some minor changes. By running it,we can get the error. whether It links to a url, file etc.

public class POIExport{
 public static void main(String[] args) throws IOException{
  Workbook wb = new HSSFWorkbook(); //or new HSSFWorkbook();
     CreationHelper createHelper = wb.getCreationHelper();

     //cell style for hyperlinks
     //by default hypelrinks are blue and underlined
     CellStyle hlink_style = wb.createCellStyle();
     Font hlink_font = wb.createFont();

     Sheet sheet = wb.createSheet("Hyperlinks");
     //number of rows
     for (int i = 0; i < 14000 ; i++){
      Row row = sheet.createRow(i);
      //number of columns
      for(int j = 0 ; j < 5; j++){
       Cell cell = row.createCell((short)j);
       cell.setCellValue("URL Link");
       Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
     FileOutputStream out = new FileOutputStream("hyperinks.xls");



So we think that It's a bug of POI 3.5 and as a substitue,we try to use the formula to solve this issue.
I have consulted with the POI development team and they say that the MS Excel can only have 64k Hyperlinks,but for this I have no idea. and I have also tested JXL which is another tool for generating the excel report and It has the same problem. for this question ,you can visit the url  for more details:

public class TestJXL {

public static void main(String[] args) throws IOException, WriteException {

String outputFile="jxl.xls";

WorkbookSettings wb = new WorkbookSettings();

wb.setLocale(new Locale("en", "EN"));

WritableWorkbook book = Workbook.createWorkbook(new File(outputFile),wb);

WritableSheet sheet= book.createSheet("Hyperlink",0);

for(int i= 0 ;i < 6;i++)


for(int j = 0;j<10921; j ++){

WritableHyperlink wh = new WritableHyperlink(i, j,

new URL(""));








It seems that by POI and JXL, the excel report which can only have 65530 Hyperlinks and if It exceeds,It will give us the error.Anyone who have solution to this problem is welcome.Thanks.

Meanwhile,if the output excel report has no format limitation,you can thinking of the following way instead.but if you have to set the format of the Hyperlink formula cell,the following method will not function.

posted on 2010-07-27 20:04 Life is no respector of any genius. 阅读(463) 评论(0)  编辑  收藏 所属分类: Java