<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Luben Park

    Java Ben 成長之路

    java中利用POI處理Excel

    package txtToExcel;

    import org.apache.poi.hssf.usermodel.HSSFCellStyle;
    import org.apache.poi.hssf.usermodel.HSSFDataFormat;
    import org.apache.poi.hssf.usermodel.HSSFFont;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFCell;

    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.util.ArrayList;

    /**
     * @author lx
     *
     */
    public class TxtToExecl {
     /** Excel 文件要存放的位置,假定在C盤下 */
     public static String outputFile = "c:\\11.xls";
     
     private static String[] DataOfLine = null;

     private static ArrayList array = new ArrayList();

     public static void main(String argv[]) {
      try {
       String fromPath = "c:/11.txt";// 取得當前目錄的路徑
       FileReader txtReader = new FileReader(fromPath);// 建立FileReader對象,并實例化為txtReader
       BufferedReader br = new BufferedReader(txtReader);// 建立BufferedReader對象,并實例化為br
       String Line = br.readLine();// 從文件讀取一行字符串

       // 判斷讀取到的字符串是否不為空
       for (int i = 0; Line != null; i++) {
        // System.out.println(Line);//輸出從文件中讀取的數據
        array.add(Line);
        Line = br.readLine();// 從文件中繼續讀取一行數據
       }
       DataOfLine = new String[array.size()];
       // System.out.println(array.size());
       array.toArray(DataOfLine);
       br.close();// 關閉BufferedReader對象
       txtReader.close();// 關閉文件
      } catch (FileNotFoundException e1) {
       e1.printStackTrace();
      } catch (IOException e1) {
       e1.printStackTrace();
      }

      try {
       // 創建新的Excel 工作簿
       HSSFWorkbook workbook = new HSSFWorkbook();
       // 在Excel工作簿中建一工作表,其名為缺省值
       // 如要新建一名為"效益指標"的工作表,其語句為:
       // HSSFSheet sheet = workbook.createSheet("效益指標");
       HSSFSheet sheet = workbook.createSheet("FeeOfTel");

       // 創建字體,設置其為紅色、粗體
       HSSFFont font = workbook.createFont();
       font.setColor(HSSFFont.COLOR_NORMAL);
       font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
       HSSFCellStyle cellStyle = workbook.createCellStyle();
       //將字體設置到中間
       cellStyle.setFont(font);
       cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
       //將文字設置到右邊
       HSSFCellStyle cellStyle1 = workbook.createCellStyle();
       cellStyle1.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    //    HSSFDataFormat format = workbook.createDataFormat();
    //    cellStyle1.setDataFormat(format.getFormat("0.00"));

       int NumLine = (array.size() / 13);
       System.out.println(NumLine);
       // 在索引0的位置創建行(最頂端的行)
       HSSFRow row = null;
       HSSFCell cell = null;
       for (int j = 0; j <= NumLine; j++) {
        row = sheet.createRow((short) j);
        for (int i = 0; i <= 12 && i + j * 13 < array.size(); i++) {
         // 在索引0的位置創建單元格(左上端
         cell = row.createCell((short) i);

         // 定義單元格為字符串類型
         cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
         cell.setEncoding(HSSFCell.ENCODING_UTF_16);
    //     cell.setCellType(HSSFCell.CELL_TYPE_STRING);
         if (j == 0 || j == NumLine - 1) {
          cell.setCellStyle(cellStyle);
          cell.setCellValue(DataOfLine[i + j * 13]);
         }
         else{
          cell.setCellStyle(cellStyle1);
          cell.setCellValue(DataOfLine[i + j * 13]);
         }
         // 在單元格中輸入一些內容
         // System.out.println(DataOfLine[i + j * 13]);
    //     cell.setCellValue(DataOfLine[i + j * 13]);
        }
       }

       // 新建一輸出文件流
       FileOutputStream fOut = new FileOutputStream(outputFile);
       // 把相應的Excel 工作簿存盤
       workbook.write(fOut);
       fOut.flush();
       // 操作結束,關閉文件
       fOut.close();
       System.out.println("文件生成...");
      } catch (Exception e) {
       System.out.println("已運行 TxtToExecl() : " + e);
      }
     }
    }

    posted on 2005-12-12 12:58 Ben 閱讀(717) 評論(4)  編輯  收藏

    評論

    # re: java中利用POI處理Excel 2006-03-21 14:04 dvpud

    邁康科技是家從事<a href="http://www.sphy.com.cn">視頻會議</a>,<a href="http://www.menjin-kaoqin.cn">門禁</a>,<a href="http://www.menjin-kaoqin.cn">考勤</a>業務的公司,在網絡<a href="http://www.vpn-firewall.com.cn">防火墻</a>,<a href="http://www.vpn-firewall.com.cn">VPN</a>工程方面有著豐富的經驗, 在樓宇<a href="http://www.jiankong-anfang.cn">安防</a> , <a href="http://www.jiankong-anfang.cn">監控</a> 等方面也有豐富案例. 并有免費的<a href="http://www.shipinhuiyi.com.cn">視頻會議</a>光盤贈送. 免費自助<a href="http://www.markcom.cn">網站建設</a>為您服務.
    咨詢電話: 021 - 51089657.  回復  更多評論   

    # re: java中利用POI處理Excel 2006-03-21 14:04 dvpud

    上海邁康科技是一家專業從事[url=http://guoqingfu.blog.ccidnet.com]視頻會議[/url]系統,瑞福特<a href="http://guoqingfu.blog.ccidnet.com">視頻會議</a>系統的企業,從事[url=http://www.blogcn.com/user89/markcom/index.html]視頻會議[/url]產品工程,<a href="http://www.blogcn.com/user89/markcom/index.html">視頻會議</a>系統集成. [url=http://markfu.cn.etlong.com]視頻會議[/url]的系統集成.<a href="http://markfu.cn.etlong.com">視頻會議</a>. 咨詢電話: 021 - 51089657.
      回復  更多評論   

    # re: java中利用POI處理Excel 2006-05-10 15:42 dvpud

    [url=http://www.blogcn.com/u/81/17/shxspin/index.html]LED顯示屏[/url]
    [url=http://shxspin.blog.hexun.com/]LED顯示屏[/url]
    [url=http://shxspin.blog.163.com]LED顯示屏[/url]
    [url="http://shxspin.blog.com.cn]LED顯示屏[/url]
    [url="http://shxspin.blog.ccidnet.com]LED顯示屏[/url]
    [url=http://blog.hc360.com/shxspin]LED顯示屏[/url]
    [url=http://blogger.org.cn/blog/blog.asp?name=shxspin]LED顯示屏[/url]
    [url=http://blog.donews.com/shxspin/]LED顯示屏[/url]
      回復  更多評論   

    # re: java中利用POI處理Excel 2006-05-10 15:43 dvpud

    [url=http://chenjiaying.blog.ccidnet.com]VPN[/url]
    [url=http://chenjiaying.blog.hexun.com]VPN[/url]
    [url=http://chenjiayingvpn.blog.tom.com]VPN[/url]
    [url=http://firewall.cn.etlong.com]VPN[/url]
    [url=http://www.vpn-firewall.com.cn]VPN[/url]
    [url=http://markcom.cn.etlong.com/]鋼絲繩[/url]
    [url=http://www.blogcn.com/u/35/83/shgss/index.html]鋼絲繩[/url]
    [url=http://hexun.com/shgss]鋼絲繩[/url]
    [url=http://shgss.blog.tom.com/]鋼絲繩[/url]
    [url=http://shgss.blog.com.cn]鋼絲繩[/url]
    [url=http://www.blogcn.com/u/35/83/shgss/index.html]鋼絲繩[/url]
    [url=http://www1.blog.163.com/-ZGeV.html]鋼絲繩[/url]  回復  更多評論   


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲avav天堂av在线网毛片| 亚洲va在线va天堂va888www| 亚洲人AV在线无码影院观看| 亚洲毛片在线免费观看| 亚洲丝袜美腿视频| 一级毛片不卡片免费观看| 亚洲av永久无码精品网站 | 2020国产精品亚洲综合网| 久草视频在线免费| 四虎亚洲精品高清在线观看| 最近免费中文字幕大全| 亚洲乱妇老熟女爽到高潮的片 | 亚洲免费人成视频观看| 亚洲欧洲日产韩国在线| 国产亚洲欧洲精品| 永久在线观看免费视频| 亚洲色欲www综合网| 猫咪社区免费资源在线观看| 亚洲欧美日韩自偷自拍| 亚洲成av人片天堂网老年人 | 国产精品亚洲专区在线播放| 亚洲国产成人久久综合一区77| 国产精品无码永久免费888| 日本人的色道免费网站| 亚洲午夜无码久久| 亚洲熟伦熟女新五十路熟妇 | 亚洲区小说区图片区| 成人电影在线免费观看| 亚洲精品永久www忘忧草| 成人免费无码大片a毛片| 国产亚洲精品第一综合| 久久精品国产亚洲AV麻豆~| 日本h在线精品免费观看| 亚洲精品乱码久久久久蜜桃| 国产亚洲精品国看不卡| 精品国产免费人成电影在线观看 | 一个人看的免费观看日本视频www| 亚洲国产精品va在线播放| 在线观看免费人成视频色9| 免费一区二区三区在线视频| 亚洲AV成人片色在线观看高潮|