教学java表格代码,Java从excel表格读取数据-用java编写代码按照正确格式读取完整excel表格的数......

从excel表格读取数据用Java代码实现批量上传写入数...

// 以下为项目中运用的jxl的核心代码

try {

Workbook book = null;

book = Workbook.getWorkbook(file);

// 获得第一个工对象

Sheet sheet = book.getSheet(0);

int rows = sheet.getRows();

if(rows>1){

Map idnomap = this.getStudentByIdnos(sheet);

for (int j = 1; j 

TStudentinfo stu = this.getStudent(sheet,sheet.getRow(j),rows,j,appmap,classmap,idnomap,state);

if(stu==null){

continue;

}

stulist.add(stu);

}

}

book.close();

// DEMO: db 操下方

xxxService.add(stulist);

}

catch (Exception e) {

System.out.println(e);

}

java中输入输出流如何把数据输出为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

row = sheet.getRow(icount);

int line=row.getPhysicalNumberOfCells();

for(int j=0;j cell1= row.getCell(j);

System.out.println(cell1 "--" icount "---" j);

}

}

//打印读取值

// System.out.println(cell.getStringCellValue());

//一输出流

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();

}

}

在java中如何读取Excel中第二个sheet表对象中数据

// 以下为项目中运用的jxl的核心代码

try {

Workbook book = null;

book = Workbook.getWorkbook(file);

// 获得第一个工对象

Sheet sheet = book.getSheet(0);

int rows = sheet.getRows();

if(rows>1){

Map idnomap = this.getStudentByIdnos(sheet);

for (int j = 1; j 

TStudentinfo stu = this.getStudent(sheet,sheet.getRow(j),rows,j,appmap,classmap,idnomap,state);

if(stu==null){

continue;

}

stulist.add(stu);

}

}

book.close();

// DEMO: db 操下方

xxxService.add(stulist);

}

catch (Exception e) {

System.out.println(e);

}

求一个java程序,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

row = sheet.getRow(icount);

int line=row.getPhysicalNumberOfCells();

for(int j=0;j cell1= row.getCell(j);

System.out.println(cell1 "--" icount "---" j);

}

}

//打印读取值

// System.out.println(cell.getStringCellValue());

//一输出流

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();

}

}

用java编写代码按照正确格式读取完整excel表格的数...

// 以下为项目中运用的jxl的核心代码

try {

Workbook book = null;

book = Workbook.getWorkbook(file);

// 获得第一个工对象

Sheet sheet = book.getSheet(0);

int rows = sheet.getRows();

if(rows>1){

Map idnomap = this.getStudentByIdnos(sheet);

for (int j = 1; j 

TStudentinfo stu = this.getStudent(sheet,sheet.getRow(j),rows,j,appmap,classmap,idnomap,state);

if(stu==null){

continue;

}

stulist.add(stu);

}

}

book.close();

// DEMO: db 操下方

xxxService.add(stulist);

}

catch (Exception e) {

System.out.println(e);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值