- 浏览: 347199 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
tianshawang:
楼主你好偏心啊,把代码给谷歌不给这里
java 实现windows资源管理器 -
tianshawang:
其实我是也想要资源管理器的代码来的。。
java 实现windows资源管理器 -
hcmfys:
lonuery 写道open file 是获取要进行复制的文件 ...
JAVA 复制 带进度条 时间 百分比 -
qq657052171:
怎么没有代码呢?
java 实现windows资源管理器 -
IT女民工:
楼主,求资源管理器代码~~~~
java 实现windows资源管理器
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
public class ExcelApp {
/**
* @param args
*/
public static void main(String[] args) throws IOException {
try {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFCellStyle style = wb.createCellStyle(); // 样式对象
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平
HSSFRow row = sheet.createRow((short) 0);
HSSFRow row2 = sheet.createRow((short) 1);
sheet.addMergedRegion(new Region(0, (short) 0, 1, (short) 0));
HSSFCell ce = row.createCell((short) 0);
ce.setEncoding(HSSFCell.ENCODING_UTF_16);// 中文处理
ce.setCellValue("项目\\日期"); // 表格的第一行第一列显示的数据
ce.setCellStyle(style); // 样式,居中
int num = 0;
for (int i = 0; i < 9; i++) { // 循环9次,每一次都要跨单元格显示
// 计算从那个单元格跨到那一格
int celln = 0;
int celle = 0;
if (i == 0) {
celln = 0;
celle = 1;
} else {
celln = (i * 2);
celle = (i * 2 + 1);
}
// 单元格合并
// 四个参数分别是:起始行,起始列,结束行,结束列
sheet.addMergedRegion(new Region(0, (short) (celln + 1), 0,
(short) (celle + 1)));
HSSFCell cell = row.createCell((short) (celln + 1));
cell.setCellValue("merging" + i); // 跨单元格显示的数据
cell.setCellStyle(style); // 样式
// 不跨单元格显示的数据,如:分两行,上一行分别两格为一格,下一行就为两格,“数量”,“金额”
HSSFCell cell1 = row2.createCell((short) celle);
HSSFCell cell2 = row2.createCell((short) (celle + 1));
cell1.setEncoding(HSSFCell.ENCODING_UTF_16);
cell1.setCellValue("数量");
cell1.setCellStyle(style);
cell2.setEncoding(HSSFCell.ENCODING_UTF_16);
cell2.setCellValue("金额");
cell2.setCellStyle(style);
num++;
}
// 在后面加上合计百分比
// 合计 在最后加上,还要跨一个单元格
sheet.addMergedRegion(new Region(0, (short) (2 * num + 1), 0,
(short) (2 * num + 2)));
HSSFCell cell = row.createCell((short) (2 * num + 1));
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("合计");
cell.setCellStyle(style);
HSSFCell cell1 = row2.createCell((short) (2 * num + 1));
HSSFCell cell2 = row2.createCell((short) (2 * num + 2));
cell1.setEncoding(HSSFCell.ENCODING_UTF_16);
cell1.setCellValue("数量");
cell1.setCellStyle(style);
cell2.setEncoding(HSSFCell.ENCODING_UTF_16);
cell2.setCellValue("金额");
cell2.setCellStyle(style);
// 百分比 同上
sheet.addMergedRegion(new Region(0, (short) (2 * num + 3), 0,
(short) (2 * num + 4)));
HSSFCell cellb = row.createCell((short) (2 * num + 3));
cellb.setEncoding(HSSFCell.ENCODING_UTF_16);
cellb.setCellValue("百分比");
cellb.setCellStyle(style);
HSSFCell cellb1 = row2.createCell((short) (2 * num + 3));
HSSFCell cellb2 = row2.createCell((short) (2 * num + 4));
cellb1.setEncoding(HSSFCell.ENCODING_UTF_16);
cellb1.setCellValue("数量");
cellb1.setCellStyle(style);
cellb2.setEncoding(HSSFCell.ENCODING_UTF_16);
cellb2.setCellValue("金额");
cellb2.setCellStyle(style);
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
System.out.print("OK");
} catch (Exception ex) {
ex.printStackTrace();
}
test();
}
/**
* 导出excel
*
* @param aServiceAccountList
*/
static void test() {
ArrayList listResult = new ArrayList();
/** test--- */
SServiceAccount sc = new SServiceAccount();
sc.set_planId(931195);
sc.set_orgId(10);
sc.set_total(13);
listResult.add(sc);
sc = new SServiceAccount();
sc.set_planId(931193);
sc.set_orgId(3);
sc.set_total(14);
listResult.add(sc);
//
sc = new SServiceAccount();
sc.set_planId(931193);
sc.set_orgId(11);
sc.set_total(15);
listResult.add(sc);
sc.set_planId(931193);
sc.set_orgId(2);
sc.set_total(16);
listResult.add(sc);
//
sc = new SServiceAccount();
sc.set_planId(931193);
sc.set_orgId(1);
sc.set_total(17);
listResult.add(sc);
//
sc = new SServiceAccount();
sc.set_planId(931193);
sc.set_orgId(10);
sc.set_total(12);
listResult.add(sc);
sc = new SServiceAccount();
sc.set_planId(9311934);
sc.set_orgId(10);
sc.set_total(19);
listResult.add(sc);
exportExcel(listResult);
}
static void exportExcel(ArrayList sServiceAccountList) {
try {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("product export");
sheet.setDefaultColumnWidth((short)45);
HSSFCellStyle style = wb.createCellStyle(); // 样式对象
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平
HSSFRow row = sheet.createRow(0);
HSSFCell orgCell = row.createCell((short) 0);
orgCell.setEncoding(HSSFCell.ENCODING_UTF_16);
orgCell.setCellValue("局向编号");
orgCell.setCellStyle(style);
HSSFCell orgName = row.createCell((short) 1);
orgName.setEncoding(HSSFCell.ENCODING_UTF_16);
orgName.setCellValue("局向名称");
orgName.setCellStyle(style);
HSSFCell productName = row.createCell((short) 2);
productName.setEncoding(HSSFCell.ENCODING_UTF_16);
productName.setCellValue("产品名称");
productName.setCellStyle(style);
HSSFCell productCountse = row.createCell((short) 3);
productCountse.setEncoding(HSSFCell.ENCODING_UTF_16);
productCountse.setCellValue("产品数目");
productCountse.setCellStyle(style);
// export excel
// 第一步 获取 局向 的的数目
int size = sServiceAccountList.size();
ArrayList tmpList = new ArrayList();
ArrayList orgList = new ArrayList();
for (int i = 0; i < size; i++) {
SServiceAccount sc = (SServiceAccount) sServiceAccountList
.get(i);
String orgidStr = sc.get_orgId() + "";
if (!tmpList.contains(orgidStr)) {
tmpList.add(orgidStr);
orgList.add(sc);
}
}
// 第二 通过局向id获取对应产品的数目
int orgSize = orgList.size();
ArrayList excelArrayList = new ArrayList();
for (int i = 0; i < orgSize; i++) {
ProductExcelInfo info = new ProductExcelInfo();
SServiceAccount sc = (SServiceAccount) orgList.get(i);
info.setOrgId(sc.get_orgId());
// 第三部 获取 orgid的 所有的产品信息
ArrayList productList = new ArrayList();
int counts = 0;
for (int j = 0; j < size; j++) {
SServiceAccount tmpSc = (SServiceAccount) sServiceAccountList
.get(j);
if (sc.get_orgId() == tmpSc.get_orgId()) {
productList.add(tmpSc);
counts += tmpSc.get_total();
}
}
info.setProductList(productList);
info.setTotalCounts(counts);
excelArrayList.add(info);
}
// 导出成excel
int excelCount = excelArrayList.size();
System.out.println("excelCount=" + excelCount);
int rowNumber = 1;
for (int i = 0; i < excelCount; i++) {
ProductExcelInfo excelProduct = (ProductExcelInfo) excelArrayList.get(i);
int totalRows = excelProduct.getProductList().size() ;
for (int j = 0; j < totalRows; j++) {
SServiceAccount sc = (SServiceAccount) excelProduct.getProductList().get(j);
HSSFRow curRow = sheet.createRow((short) (rowNumber + j));
//orgId
if(j==0) {
HSSFCell orgIdCell = curRow.createCell((short) 0);
sheet.addMergedRegion(new Region(rowNumber, (short) ( 0), rowNumber+totalRows,(short) ( 0)));
orgIdCell.setEncoding(HSSFCell.ENCODING_UTF_16);
orgIdCell.setCellValue(excelProduct.getOrgId() + "");
orgIdCell.setCellStyle(style);
//orgName
HSSFCell orgNameCell = curRow.createCell((short) 1);
sheet.addMergedRegion(new Region(rowNumber, (short) ( 1), rowNumber+totalRows,(short) ( 1)));
orgNameCell.setEncoding(HSSFCell.ENCODING_UTF_16);
orgNameCell.setCellValue(excelProduct.getOrgId() + "");
orgNameCell.setCellStyle(style);
}
//产品名称
HSSFCell productNameCell = curRow.createCell((short) 2);
productNameCell.setEncoding(HSSFCell.ENCODING_UTF_16);
productNameCell.setCellValue(sc.get_planId() + "");
productNameCell.setCellStyle(style);
//产品数目
HSSFCell productCountCell = curRow.createCell((short) 3);
productCountCell.setEncoding(HSSFCell.ENCODING_UTF_16);
productCountCell.setCellValue(sc.get_total() + "");
productCountCell.setCellStyle(style);
}
//统计数目的 行
HSSFRow statRow = sheet.createRow((short) (rowNumber + totalRows));
HSSFCell totalCell = statRow.createCell((short) 2);
totalCell.setEncoding(HSSFCell.ENCODING_UTF_16);
totalCell.setCellValue( "合计");
totalCell.setCellStyle(style);
HSSFCell numCountCell = statRow.createCell((short) 3);
numCountCell.setEncoding(HSSFCell.ENCODING_UTF_16);
numCountCell.setCellValue(excelProduct.getTotalCounts());
numCountCell.setCellStyle(style);
rowNumber += totalRows + 1;
}
FileOutputStream fileOut = new FileOutputStream("export.xls");
wb.write(fileOut);
fileOut.close();
System.out.print("OK");
} catch (Exception e) {
e.printStackTrace();
}
}
}
发表评论
-
Java服务器的JSON数据包三重加密算法(转载)
2015-06-03 19:30 1211mina的粘包拆包其实是蛮简单的,只是一开始没搞清楚原理。 J ... -
java ssl (转载)
2014-12-25 17:50 785某项目的业务系统要求 ... -
table
2014-05-27 00:13 764table ... -
java 删除目录
2013-08-01 21:45 834import java.io.File; pub ... -
负载均衡方法
2013-06-05 22:26 1051•随机:负载均衡方法 ... -
&#x 格式数据转换
2013-05-22 11:52 3065import java.io.UnsupportedEnc ... -
Java数据库连接
2012-11-22 10:42 804Java数据库连接(JDBC)由一组用 Java 编程语言编写 ... -
http post
2012-10-31 11:51 899package test.net; import ... -
Java proxy 代理访问网络(转)
2012-10-31 10:12 1454How to make your Java applicati ... -
java版mini编辑器
2012-10-11 15:40 840习惯用Editplus来查看源代码,但是没有代码导航功能,想看 ... -
excel 导入
2011-12-16 18:03 1041package *.*; import java.uti ... -
EVAL_BODY_INCLUDE
2011-08-09 10:19 1358EVAL_BODY_INCLUDE:把Body读入存在的输出流 ... -
jrebel的使用
2011-07-06 18:21 939-noverify -javaagent:E:\jrebe ... -
java 实现windows资源管理器
2011-06-27 00:00 2128最近在使用linux的界面,有时候觉得界面很难用,不如wind ... -
Linux下java环境变量设置的完整步骤
2010-10-29 13:32 952从java.sun.com上下载JDK的安装文件,一般是jdk ... -
设置头部,直接下载文件
2010-09-26 10:34 1003string dir = SysSetting.Wave ... -
java 地图查看器
2010-07-25 23:07 1160/** * @(#)GisApp.java * ... -
中国移动 联通 电信 模拟网关服务器
2010-03-29 21:55 1951/Files/hcmfys/SngServer.rar -
basic64
2010-02-09 14:29 1728using System; using System. ... -
JAVA 复制 带进度条 时间 百分比
2008-05-22 09:27 2293写得不太好。如果喜欢就下载/** * @(#)Jprogr ...
相关推荐
javaexcel导入数据库.pdf
struts+hibernate实现excel导入数据库 注意:Excel导入是指读服务器端的数据,也就是说,如果想用客户端的Excel是需要把Excel文件先上传到服务器上的,然后再导入,我也是前几天才发现的。
java Excel导入导出
* 此代码是完成从excel导入电话号码,将正确的电话号码保存到set集合中,因为set集合对于重复的值会覆盖,所以达到了去重复的值的用例,并累计了不正确的电话号码的个数,对电话号码进行了验证有效性。所需要的 dom4...
java excel 读写 java excel 导入数据库 部分来自网络,现整理供同行们使用
java实现Excel导入
java excel导入导出,里面的读写excel的代码已经写好了。
用maven构建的java excel导入mysql的demo
java excel导入导出数据库表内容 直接调用写好的方法,修改下数据库名和路径即可
Excel源代码,导入导出各种工具类 <groupId>org.apache.poi <artifactId>poi <groupId>org.apache.poi <artifactId>poi-scratchpad 代码实例: String path = ""; byte[] bytes; vo.setCurrentPage(0); vo....
用Java实现的Excel的导入导出,简洁明了,高质量代码。
java EXCEL导入导出工具类 包含具体代码 课根据需求改造
java excel导入数据库
Java Excel 导入数据
这个是使用java语言 poi导入excel到数据库中,同时使用了xml对excel的每个单元格数据进行了非空验证。经测试,导入数据库成功。
Java excel导入导出;工具类+注解的实现;比较适用于做公共excel导入导出;还提供一个模板样例,样例中前端请求用的是axios,后台是Java实现。有任何问题,随时提问。
javaexcel导入数据库[借鉴].pdf