<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]  回復  更多評論   


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


    網站導航:
     
    主站蜘蛛池模板: 日韩精品极品视频在线观看免费| 2022免费国产精品福利在线 | 亚洲日韩一页精品发布| 色欲aⅴ亚洲情无码AV| 在线a毛片免费视频观看| 亚洲成a人片在线观看精品| 青苹果乐园免费高清在线| 亚洲人成网站在线播放2019| 亚洲av第一网站久章草| 免费理论片51人人看电影| jzzijzzij在线观看亚洲熟妇| 国产精品麻豆免费版| 美女黄色毛片免费看| 丁香五月亚洲综合深深爱| 18禁在线无遮挡免费观看网站| 亚洲成熟xxxxx电影| 久九九精品免费视频| 亚洲欧美日韩中文二区| 免费在线观看黄网| 中文在线免费视频| 亚洲午夜免费视频| 日韩精品无码区免费专区| 风间由美在线亚洲一区| 国产亚洲精久久久久久无码AV| 久久黄色免费网站| 亚洲国产日韩在线成人蜜芽| 在线免费观看色片| 一级毛片人与动免费观看 | 亚洲欧洲国产成人精品| 国产99视频精品免费视频76| 亚洲国产精品无码AAA片| 一级做a毛片免费视频| 亚洲av综合avav中文| 无码少妇一区二区浪潮免费| 婷婷亚洲久悠悠色悠在线播放| 91高清免费国产自产| 国产精品亚洲精品日韩动图| 亚洲高清国产AV拍精品青青草原| 1a级毛片免费观看| 成在线人直播免费视频| 久久亚洲日韩看片无码|