是不是读取excel内容。是的话如下。不是,抢座

解决方案 »

  1.   

    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.text.SimpleDateFormat;
    import jxl.Cell;
    import jxl.CellType;
    import jxl.DateCell;
    import jxl.Sheet;
    import jxl.Workbook;
    import org.apache.log4j.*;/**
     * 
     * @author Guopengtao
     * @date 2007-8-9 Discription 本类是用于将xls文件内容导出到txt文件文件中。内容以|+|分隔
     */
    public class ExcelFileToTxt {

    static Logger log = Logger.getLogger(ExcelFileToTxt.class);
    /**
     * 
     * @param filePath
     * @return String[][] xls文件见内容存放的字符串数组
     */
    private static String[][] readExcel(String filePath) {
    String[][] strTemp = null;
    try {
    InputStream is = new FileInputStream(filePath);
    jxl.Workbook wb = Workbook.getWorkbook(is);//转换警告,暂无定论
    Sheet rs = wb.getSheet(0);//默认为第一Sheet
    int rows = rs.getRows();
    int cols = rs.getColumns();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");// 在1处日期内容按YYYYMMDD格式提取
    strTemp = new String[rows][cols];
    for (int i = 0; i < rows; i++) {
    for (int j = 0; j < cols; j++) {
    Cell c = rs.getCell(j, i);
    if (c.getType() == CellType.DATE) {
    strTemp[i][j] = formatter.format((((DateCell) c)// 1
    .getDate()));
    } else {
    strTemp[i][j] = c.getContents().toString().trim();
    }
    }
    }
    wb.close();
    } catch (Exception ex) {

    log.debug("转换xls文件失败"+ex.getMessage());
    }
    return strTemp;
    }
    /**
     * 
     * @param filepath
     * @return String 将存放xls文件的字符数组按照|+|格式放入字符串中
     */
    public String getFileByte(String filepath) {
    String[][] out = null;
    out = readExcel(filepath);
    int rn = out.length;
    int cn;
    if (rn > 0)
    cn = out[0].length;
    else
    cn = 0;
    String str = "";
    for (int i = 0; i < rn; i++) {
    for (int j = 0; j < cn; j++) {
    str = str + out[i][j].toString().trim();
    if (j < cn - 1) {
    str = str + "|+|";
    }
    }
    str = str + "\r\n";
    }
    return str;
    }
    }
    下载jxl.jar
      

  2.   

    不是是取得excel里所嵌控件text box里的值,不过还是谢谢你哈
      

  3.   

    难道POI不支持excel里操纵text box?
      

  4.   

    那别的技术可以吗?只要是用java能够操纵excel里的text box就可以。
      

  5.   

    我也是这个问题,POI能够操纵excel里的text box控件就可以。坐等高人解答~