网站首页 美容小常识 享受生活 东方时尚 识真假 高奢 资讯 游戏攻略 搞笑段子
当前位置:品位站 > 享受生活 > 心理

java怎么操作excel转xml文件

栏目: 心理 / 发布于: / 人气:2.08W
java怎么操作excel转xml文件

百度搜索圈T社区 免费行业视频教程

package a

import InputStream

import ection

import erManager

import aredStatement

import Cell

import Row

import Sheet

import Workbook

/**

*

* @author asima

* @data 2006-10-18

*/

public class XlsToAccess

{

HSSFSheet globalSheet = null

/*读取一个指定单元格内容*/

public String readCellValue(String pos)

{

int xpos

short ypos

int cellType /*取得此单元格的类型 0-Numeric,1-String,3-null*/

String result /*返回取得的单元格的值*/

ypos = (short) (perCase()At(0) - 65)

xpos = eInt(tring(1, th())) - 1

HSSFRow row = null /* 定义excel中的行 */

HSSFCell cell = null /* 定义excel中的单元格 */

/* 根据xPos和yPos取得单元格 */

row = ow(xpos)

cell = ell(ypos)

/** **************此处如果是空需要修改********************************** */

cellType = ellType()

switch (cellType)

{

case 0: /* 0-Numeric */

result = eOf(umericCellValue())

break

case 1: /* 1-String */

result = tringCellValue()

break

case 3: /* 3-null */

result = ""

break

default:

result = ""

break

}

return result

}

/*读取excel文件并把内容插入到access表中*/

public void insertIntoTable() throws Exception

{

// 创建对Excel工作簿文件的引用

HSSFWorkbook workbook =

new HSSFWorkbook(new FileInputStream("D:/temp/"))

// 获得一个sheet

globalSheet = heetAt(0)

String value1 = readCellValue("c1")

String value2 = readCellValue("c2")

String value3 = readCellValue("c3")

String value4 = readCellValue("c4")

tln(value1)

tln(value2)

/* 插入数据库 */

ame("OdbcDriver")

String url = "jdbc:odbc:asima"

Connection conn = onnection(url)

PreparedStatement stmt =

areStatement("insert into custom values(?,?,?,?)")

// 定义查询的SQL语句

tring(1, value1)

tring(2, value2)

tring(3, value3)

tring(4, value4)

uteUpdate

Tags:XML java 文件 excel