随笔 - 141,  文章 - 0,  评论 - 10,  阅读 - 16万

03版excel,需要用到jxl.jar这个jar包

复制代码
package test.poi;

import java.io.File;
import java.io.IOException;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

//03版excel
public class getExcel {
    public static void main(String[] args){
        show03Excel();
    }
    public static void show03Excel(){
        Sheet sheet;
        Workbook book = null;
        try {
            book= Workbook.getWorkbook(new File("F:\\Book1.xls"));
        } catch (BiffException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
//        System.out.println(book);
        //获得第一个工作表对象(ecxel中sheet的编号从0开始,0,1,2,3,....)
        sheet=book.getSheet(0);
        int rows = 0;
        int r=0,l=0;
        String value=null;
        while(sheet.getCell(0,r).getContents()!=""&&sheet.getCell(0,r).getContents()!=null){
            r++;
        }
        while(sheet.getCell(l,0).getContents()!=""&&sheet.getCell(l,0).getContents()!=null){
            l++;
        }
        for(int i=0;i<(r);i++){
            for(int j=0;j<(l);j++)
                System.out.print(sheet.getCell(j,i).getContents()+"\t\t");
            System.out.println();
        }
    }
}
复制代码

07版EXCEL,需要用到poi这个jar包

复制代码
package test.poi;

import java.io.IOException;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class get07Excel {
    public static void main(String[] arg){
        show07excel();
    }
    public static void show07excel(){
        XSSFWorkbook xwb =null;
        try {
            xwb= new XSSFWorkbook("F:\\Book1.xlsx");
        } catch (IOException e) {
            e.printStackTrace();
        }
        XSSFSheet sheet=xwb.getSheetAt(0);
        XSSFRow row;
        String cell;
        int r=0,l=0;
        row = sheet.getRow(0);
        while(row.getCell(l).toString()!=""&&row.getCell(l).toString()!=null){
            l++;
        }
        while(row.getCell(0).toString()!=""&&row.getCell(0).toString()!=null){
            r++;
            row = sheet.getRow(r);
        }
        System.out.println("the rows is "+r+" and the number of one row is "+l);
        // 循环输出表格中的内容
        for (int i = sheet.getFirstRowNum(); i < r; i++)
        {
            row = sheet.getRow(i);
            for (int j = row.getFirstCellNum(); j < l; j++)
            {
                cell = row.getCell(j).toString();
                System.out.print(cell + "\t");
            }
            System.out.println("");
        }
    }
}
复制代码
posted on   程序员丁先生  阅读(1255)  评论(1编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示