package com.action;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import com.action.base.BaseAction;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
@Namespace("/")
@Action(value = "xxxxxAction", results = { })
public class XxxxxAction extends BaseAction implements ModelDriven<xx> {
public void daochu() throws WriteException, IOException {
String content = xx.getIdss();
WritableWorkbook wwb = null;
WritableSheet sheet = null;
ServletActionContext.getResponse().setContentType("application/vnd.ms-excel");
String sheetName = "Sheet1";
sheetName = sheetName.replaceAll(":", "").replaceAll("[)]", "").replaceAll("[(]", "");
ServletActionContext.getResponse().addHeader("Content-Disposition", "attachment; filename=" + new String(sheetName.getBytes("GBK"), "ISO-8859-1") + ".xls");
OutputStream os = ServletActionContext.getResponse().getOutputStream();
wwb = Workbook.createWorkbook(os);
wwb.setProtected(true);
sheet = wwb.createSheet(sheetName, 0);
int row = 0;
int col = 0;
Label label = null;
if (sheetName.trim().length() > 30) {
label = new Label(col, row, sheetName);
sheet.addCell(label);
row++;
}
WritableCellFormat cellFormat = new WritableCellFormat();
cellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
List listBody = getContent(content);
Map<String, Boolean> map = new HashMap<String, Boolean>();
for (Object tdd : listBody) {
TD td = (TD) tdd;
if (td == null) {
row++;
col = 0;
continue;
}
if (td.colspan > 1 || td.rowspan > 1) {
sheet.mergeCells(col, row, col + td.colspan - 1, row + td.rowspan - 1);
for (int i = col; i <= col + td.colspan - 1; i++) {
for (int j = row; j <= row + td.rowspan - 1; j++) {
map.put(i + "-" + j, true);
}
}
}
label = new Label(col, row, td.content);
label.setCellFormat(cellFormat);
if (td.width != 1)
sheet.setColumnView(col, td.width);
sheet.addCell(label);
map.put(col + "-" + row, true);
col += td.colspan;
}
wwb.write();
wwb.close();
}
private String getCaption(String content) {
int begin = content.indexOf("<CAPTION");
int end = content.indexOf("</CAPTION>");
if (begin == -1 || end == -1) {
return null;
}
begin = content.indexOf(">", begin);
if (begin == -1) {
return null;
}
return content.substring(begin + 1, end);
}
public List getContent(String content) throws UnsupportedEncodingException {
int begin = -1;
int end = -1;
int index = -1;
String numberStr;
int number;
String[] tables = content.split("</TABLE>");
List list = new ArrayList();
for (int i = 3; i < tables.length; i++) {
String table = tables[i];
table = table.replace("</TBODY>", "");
String[] trs = table.split("</TR>");
for (String tr : trs) {
number = 1;
String[] ss = tr.split("</TD>");
for (String s : ss) {
begin = s.indexOf("<TD");
if (begin == -1) {
continue;
}
s = s.substring(begin + 3);
index = s.indexOf(">");
TD td = new TD();
begin = s.indexOf("rowSpan=");
if (begin != -1) {
end = s.indexOf(" ", begin);
if (end == -1) {
end = index;
}
numberStr = s.substring(begin + 8, end).replace('"', ' ').replace('\'', ' ').trim();
number = Integer.parseInt(numberStr);
td.rowspan = number;
}
begin = s.indexOf("colSpan=");
if (begin != -1) {
end = s.indexOf(" ", begin);
index = s.indexOf(">", begin);
if (end == -1) {
end = index;
}
if (end > index) {
end = index;
}
numberStr = s.substring(begin + 8, end).replace('"', ' ').replace('\'', ' ').trim();
number = Integer.parseInt(numberStr);
td.colspan = number;
}
begin = s.indexOf("DIV style=\"WIDTH: ");
if (begin != -1) {
end = s.indexOf("px", begin);
index = s.indexOf(">", begin);
if (end == -1) {
end = index;
}
if (end > index) {
end = index;
}
numberStr = s.substring(begin + 18, end).replace('"', ' ').replace('\'', ' ').trim();
number = Integer.parseInt(numberStr) / 5;
td.width = number;
}
td.content = s.substring(index + 1).replaceAll("\\<.*?\\>", "").replaceAll(" ", "").replaceAll(" ", "").trim();
list.add(td);
}
list.add(null);
}
}
return list;
}
}
class TD {
int rowspan = 1;
int colspan = 1;
int width = 1;
String content;
}

beans9
- 粉丝: 30
最新资源
- 基于Cortex-M0架构的FPGA可编程软核处理器完整实现_包含UART串口通信模块_定时器外设驱动_KeilMDK开发环境支持_VerilogHDL硬件描述语言源码_适用于嵌入.zip
- HMCL微软登录白屏问题解决方案_硬核修改HMCL源码实现微软账号登录_通过代码注入和参数传递绕过内置浏览器限制_提供自动化网页操作工具获取登录参数_支持Minecraft正版验证.zip
- 智能生产管理系统S-PMS前端项目_基于Vue3和TypeScript构建的企业级智能制造解决方案_集成MES制造执行系统_WMS仓库管理系统_ERP企业资源计划_QMS质量管理系.zip
- 基于JavaSSH框架实现的PKI证书全生命周期管理系统_包含CA证书签发_用户证书申请_管理员审核_证书下载安装_证书统一管理_Java密钥工具调用_数据库存储证书信息_MVC架.zip
- LuSrackhall_KeyTone_7244_1755583598320.zip
- 换热器校核计算与性能分析软件_基于热力学原理与传热学公式的换热器热力性能计算_用于化工_能源_电力等工业领域换热设备的设计校核与运行优化_支持管壳式_板式_螺旋板式等多种换热器类型.zip
- 企鹅电竞开发的跨平台高性能动画播放器VAP_支持直播礼物特效短视频特效预览的解决方案_采用硬件解码和ijk软解码双引擎_支持透明背景和粒子特效_相比WebpApng具有更高压缩率_.zip
- tako511_ruanchuang_29388_1755583611929.zip
- 基于Java工厂代理模式的企业级应用开发框架_采用JDK180_191和Maven352构建的IntelliJIDEA2017开发环境_面向软件开发初学者和设计模式学习者的.zip
- 基于PyTorch深度学习框架的单摄像头人群追踪系统_实现高精度实时人群检测与多目标跟踪_适用于公共安全监控与人群流量统计_采用FairMOT算法与ByteTrack追踪核心_支持.zip
- nicball_riscfw_7244_1755583624652.zip
- 核酸检测结果自动识别与统计管理系统_基于OCR技术和颜色识别的核酸检测结果自动采集系统_用于高校核酸检测结果自动识别与数据汇总_采用easyocr图像文字提取和opencv颜色识别.zip
- 基于虹软免费人脸识别库Android版开发的Delphi1023封装SDK_专门针对二代身份证芯片低像素照片优化的人证核验比对系统_实现高效准确的人证合一验证功能_包含人脸特征.zip
- 鱼声FM跨平台音乐发现软件_专注于纯音乐后摇滚电子乐国风音乐等小众音乐类型_为喜欢独立音乐的用户提供个性化音乐推荐_支持WindowsLinuxMacOS三大平台_采用NET技术.zip
- dister是一款轻量级高性能的分布式集群管理软件_实现了分布式软件架构中的服务配置管理中心_服务注册与发现_服务健康检查_服务负载均衡等核心组件_基于RAFT算法实现分布式一致性.zip
- 基于Python与Neo4j构建的中文医疗知识图谱智能问答系统_包含疾病症状治疗药物检查科室等实体关系_用于医疗信息查询与智能诊断辅助_采用py2neo构建知识图谱pyahocor.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


