kiwiwings

Comment extraction on 598948.xlsx

Aug 1st, 2014
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.24 KB | None | 0 0
  1. package org.apache.poi.xssf.usermodel;
  2.  
  3. import java.io.File;
  4.  
  5. import org.apache.poi.ss.usermodel.Cell;
  6. import org.apache.poi.ss.usermodel.Comment;
  7. import org.apache.poi.ss.usermodel.Row;
  8. import org.junit.Test;
  9.  
  10. public class TikaTest {
  11.  
  12.     @Test
  13.     public void testme() throws Exception {
  14.         int comm_cnt = 0;
  15.         int comm_char_cnt = 0;
  16.         int auth_cnt = 0;
  17.         int auth_char_cnt = 0;
  18.        
  19.         XSSFWorkbook wb = new XSSFWorkbook(new File("598948.xlsx"));
  20.         for (XSSFSheet s : wb) {
  21.             for (Row r : s) {
  22.                 for (Cell c : r) {
  23.                     Comment cm = c.getCellComment();
  24.                     if (cm != null) {
  25.                         comm_cnt++;
  26.                         comm_char_cnt += cm.getString().getString().length();
  27.                         String author = cm.getAuthor();
  28.                         if (author != null) {
  29.                             auth_cnt++;
  30.                             auth_char_cnt += author.length();
  31.                         }
  32.                     }
  33.                 }
  34.             }
  35.         }
  36.         wb.close();
  37.         System.out.println(comm_cnt+" "+comm_char_cnt+" "+auth_cnt+" "+auth_char_cnt);
  38.         // prints 103 17281 103 192
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment