乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > java中poi如何得到excel 单元格地址?-java读取excel单元格,java读取excel合并单元格

java中poi如何得到excel 单元格地址?-java读取excel单元格,java读取excel合并单元格

作者:乔山办公网日期:

返回目录:excel表格制作


使用java poi
package webservice;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

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

public class ExcelController {

@SuppressWarnings("deprecation")
public void excel() throws FileNotFoundException, IOException{

String filename = "d:\\excel.xls";
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filename));
//按名引用excel工作表
// HSSFSheet sheet = workbook.getSheet("JSP");
//也可以用以下方式来获取excel的工作表,采用工作表的索引值
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFRow row ;
HSSFCell cell1;
int rows=sheet.getLastRowNum();
for(int icount=0;icount<rows;icount++){
row = sheet.getRow(icount);
int line=row.getPhysicalNumberOfCells();
for(int j=0;j<line;j++){
cell1= row.getCell(j);
System.out.println(cell1+"--"+icount+"---"+j);
}
}
//打印读取值
// System.out.println(cell.getStringCellValue());

//新建e799bee5baa6e79fa5e98193e78988e69d83337一输出流
FileOutputStream fout = new FileOutputStream(filename); //PS:filename 是你另存为的路径,不处理直接写入模版文件
//存盘
workbook.write(fout);
fout.flush();
//结束关闭
fout.close();

}

public HSSFCell getCell(HSSFRow row, int index) {

// 取得分发日期单元格
HSSFCell cell = row.getCell(index);

// 如果单元格不存在
if (cell == null) {

// 创建单元格
cell = row.createCell(index);
}

// 返回单元格
return cell;
}

public static void main(String[] args) {
ExcelController ec = new ExcelController();
try {
ec.excel();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

        // 大概这copy么个思路,没验证~
public static String getlocationFromCell(Cell cell) {
int colIndex = cell.getColumnIndex();
// note: 行的序列号开始于1 
int rowIndex = cell.getRowIndex()+1;
String colStr = null;
if(colIndex<26) {
colStr = (char)(colIndex+65)+"";
} else {
char a = (char)(colIndex/26+64);
char b = (char)(colIndex%26+65);
colStr = a+""+b;
}
return colStr+rowIndex;
}

cell.getRowIndex();// 行号从0开始计数

cell.getColumnIndex();// 列号从0开始计数

最笨的方法,设置copy一个字符数组char A {'A','B'..........'Z'}
将输入的地址解析为字符数组B{'B','2'}
for(int i=0,i<A.length,i++){
if(A[i]==B[0]){
B[0]="'"+i+"'";
}
}
此时B{'1','2'}
再对表格取 row , sheet.createRow(Integer.paraInt(B[0]));

再取cell row.createCell(Integer.paraInt(B[1])-1)

相关阅读

关键词不能为空
极力推荐
  • 如何将<em>excel</em>表中的数据<em>导入arcgis</em&

  • 如果是shp格式,直接用excel打开dbf文件。否则,加载数据,layer右键打开属性表,找到一个export按钮,导出为dbf,excel可以直接打开。export按钮,不同的版本位置不一样,需要仔细找。导

ppt怎么做_excel表格制作_office365_word文档_365办公网