package cn.jerry.mouse.property_tools;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ExcelProperties {
public void exportToFile(String excelFileName,int keyColumn,int valueColumn,String exportFileName) throws Exception {
File excelFile = new File(excelFileName);
File exportFile = new File(exportFileName);
BufferedWriter bw = new BufferedWriter(new FileWriter(exportFile));
Workbook workbook = Workbook.getWorkbook(excelFile);
Sheet[] sheet = workbook.getSheets();
Cell[] keyCell;
Cell[] valueCell;
String key;
String value;
for(int sheetIndex=0;sheetIndex<sheet.length;sheetIndex++)
{
keyCell = sheet[sheetIndex].getColumn(keyColumn);
valueCell = sheet[sheetIndex].getColumn(valueColumn);
for(int rowIndex=1;rowIndex<keyCell.length;rowIndex++) //第一行作为标题栏,忽略掉
{
key = keyCell[rowIndex].getContents();
value = valueCell[rowIndex].getContents();
if(key.trim()!="")
bw.write(key+"="+value+"\r\n");
}
}
bw.close();
workbook.close();
}
private boolean isFileValid(String excelFileName) throws Exception
{
try {
File excelFile = new File(excelFileName);
Workbook workbook = Workbook.getWorkbook(excelFile);
workbook.getSheets();
workbook.close();
} catch (BiffException e) {
throw new Exception("不支持此文件格式,仅支持Excel 2003");
}
return true;
}
public static void main(String[] args) throws Exception
{
ExcelProperties excelUtil = new ExcelProperties();
String excelFilePath = "D:\\res.xls";
String exportCNFilePath = "D:\\res_zh_CN.properties";
String exportENFilePath = "D:\\res_en_US.properties";
String exportDefaultFilePath = "D:\\res.properties";
int keyColumn = 0;
int valueColumn;
if(args.length==4)
{
excelFilePath = args[0];
exportCNFilePath = args[1];
exportENFilePath = args[2];
exportDefaultFilePath = args[3];
}
else if(args.length!=0)
{
System.out.println("Usage: java -jar ExcelProps.jar excelFilePath exportCNFilePath exportENFilePath excelFilePath");
return;
}
excelUtil.isFileValid(excelFilePath);
System.out.println("Begin to exprort from excelFile: "+excelFilePath);
valueColumn = 1;
excelUtil.exportToFile(excelFilePath, keyColumn, valueColumn, exportCNFilePath);
System.out.println("Config file in Chinese exported: "+exportCNFilePath);
valueColumn = 2;
excelUtil.exportToFile(excelFilePath, keyColumn, valueColumn, exportENFilePath);
System.out.println("Config file in English exported: "+exportENFilePath);
valueColumn = 1;
excelUtil.exportToFile(excelFilePath, keyColumn, valueColumn, exportDefaultFilePath);
System.out.println("Config file in default language exported: "+exportDefaultFilePath);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1.用途: 通过excel来集中管理资源文件,此工具用于从excel文件中生成资源文件,默认支持两种语言,不过可以简单修改代码来支持更多语言。 2.优点: 每次添加资源文件时,可以只在excel文件集中编辑,不必到各个资源文件中去编辑。 Excel文件内容样例: 资源标识 中文 英文 product.id 产品ID Product ID product.name 产品名称 Product Name">1.用途: 通过excel来集中管理资源文件,此工具用于从excel文件中生成资源文件,默认支持两种语言,不过可以简单修改代码来支持更多语言。 2.优点: 每次添加资源文件时,可以只在excel文件集中编辑,不必到各个资源文件中? [更多]
资源推荐
资源详情
资源评论
收起资源包目录
.zip (12个子文件)
资源文件生成工具
工具
runExcelProps.bat 119B
ExcelProps.jar 507KB
样例
res_zh_CN.properties 80B
res.properties 80B
res_en_US.properties 92B
res.xls 7KB
源代码
ExcelProps
.project 386B
src
cn
jerry
mouse
property_tools
ExcelProperties.java 3KB
.settings
org.eclipse.jdt.core.prefs 634B
.classpath 348B
bin
cn
jerry
mouse
property_tools
ExcelProperties.class 3KB
jxl.jar 504KB
共 12 条
- 1
资源评论
尹星
- 粉丝: 5
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功