parent
4ca1131e85
commit
a0af38f603
@ -1,36 +0,0 @@
|
||||
import com.raqsoft.dm.Sequence;
|
||||
import com.raqsoft.report.model.ReportDefine;
|
||||
import com.raqsoft.report.usermodel.INormalCell;
|
||||
import com.raqsoft.report.util.ReportUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class DeleteBoldTitle {
|
||||
public static void main(String[] args) throws Throwable {
|
||||
// 设置报表授权文件
|
||||
File flic = new File("./reportTrialLicense20211231.xml");
|
||||
FileInputStream lis = new FileInputStream(flic);
|
||||
Sequence.readLicense(Sequence.P_RPT, lis);
|
||||
|
||||
|
||||
FileInputStream fis = new FileInputStream("E:\\Work\\dsMin\\Report2020\\001各级各类教育校数、教职工数、专任教师情况.rpx");
|
||||
ReportDefine rd = (ReportDefine) ReportUtils.read(fis);
|
||||
int row = rd.getRowCount();//获取报表行数
|
||||
int col = rd.getColCount();//获取报表列数
|
||||
|
||||
for (int i = 1; i <= row; i++)
|
||||
for (int j = 1; j <= col; j++) {
|
||||
INormalCell inc = rd.getCell(i, (short) j);
|
||||
inc.setCellStyleName(null);
|
||||
//System.out.println(inc.getCellStyleName());
|
||||
}
|
||||
System.out.println(row);
|
||||
System.out.println(col);
|
||||
OutputStream os = new FileOutputStream("d:\\1.rpx");
|
||||
ReportUtils.write(os, rd);
|
||||
System.out.println("恭喜,导出成功!");
|
||||
}
|
||||
}
|
@ -1,171 +0,0 @@
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import jxl.Cell;
|
||||
import jxl.Range;
|
||||
import jxl.Sheet;
|
||||
import jxl.Workbook;
|
||||
import jxl.format.Alignment;
|
||||
import jxl.format.CellFormat;
|
||||
import jxl.format.Colour;
|
||||
import jxl.format.VerticalAlignment;
|
||||
|
||||
public class ExcelTransformHtml {
|
||||
public static String getExcelInfo(File sourcefile) throws Exception {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
InputStream is = new FileInputStream(sourcefile);
|
||||
Workbook rwb = Workbook.getWorkbook(is);
|
||||
Sheet sheet = rwb.getSheet(0);
|
||||
int colnum = sheet.getColumns();
|
||||
int rownum = sheet.getRows();
|
||||
Map<String, String> map[] = getRowSpanColSpanMap(sheet);
|
||||
sb.append("<table border='1' cellspacing='0'>");
|
||||
for (int row = 0; row < rownum; row++) {
|
||||
sb.append("<tr>");
|
||||
for (int col = 0; col < colnum; col++) {
|
||||
Cell cell = sheet.getCell(col, row);
|
||||
String content = cell.getContents();
|
||||
CellFormat cellFormat = cell.getCellFormat();
|
||||
if (map[0].containsKey(row + "," + col)) {
|
||||
String pointString = map[0].get(row + "," + col);
|
||||
map[0].remove(row + "," + col);
|
||||
int bottomeRow = Integer.valueOf(pointString.split(",")[0]);
|
||||
int bottomeCol = Integer.valueOf(pointString.split(",")[1]);
|
||||
int rowSpan = bottomeRow - row + 1;
|
||||
int colSpan = bottomeCol - col + 1;
|
||||
sb.append("<td rowspan= '" + rowSpan + "' colspan= '" + colSpan + "' ");
|
||||
} else if (map[1].containsKey(row + "," + col)) {
|
||||
map[1].remove(row + "," + col);
|
||||
continue;
|
||||
} else {
|
||||
sb.append("<td ");
|
||||
}
|
||||
if (cellFormat != null) {
|
||||
Alignment alignment = cellFormat.getAlignment();
|
||||
sb.append("align='" + convertToHtmlGrammer(alignment) + "' ");
|
||||
VerticalAlignment verticalAlignment = cellFormat.getVerticalAlignment();
|
||||
sb.append("valign='" + convertToHtmlGrammer(verticalAlignment) + "' ");
|
||||
// sb.append("style='color:" + convertToHtmlGrammer(cellFormat.getFont().getColour()) + ";"); //
|
||||
Colour bgcolour = cellFormat.getBackgroundColour();
|
||||
// sb.append("background-color:" + convertToHtmlGrammer(bgcolour) + ";"); //
|
||||
// Colour bottomColour = cellFormat.getBorderColour(Border.BOTTOM); //
|
||||
// Colour leftColour = cellFormat.getBorderColour(Border.LEFT);
|
||||
// Colour rightColour = cellFormat.getBorderColour(Border.RIGHT);
|
||||
// Colour topColour = cellFormat.getBorderColour(Border.TOP);
|
||||
|
||||
// System.out.print("bottomColour:" +
|
||||
// bottomColour.getDescription());
|
||||
// System.out.print(" leftColour:" +
|
||||
// leftColour.getDescription());
|
||||
// System.out.print(" rightColour:" +
|
||||
// rightColour.getDescription());
|
||||
// System.out.println(" topColour:" +
|
||||
// topColour.getDescription());
|
||||
|
||||
// sb.append("border-color:" + convertToHtmlGrammer(bottomColour) + ";"); //
|
||||
sb.append("' ");
|
||||
}
|
||||
sb.append(">");
|
||||
if (content == null || "".equals(content.trim())) {
|
||||
sb.append(" ");
|
||||
} else {
|
||||
sb.append(content);
|
||||
}
|
||||
sb.append("</td>");
|
||||
}
|
||||
sb.append("</tr>");
|
||||
}
|
||||
sb.append("</table>");
|
||||
rwb.close();
|
||||
is.close();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, String>[] getRowSpanColSpanMap(Sheet sheet) {
|
||||
Map<String, String> map0 = new HashMap<String, String>();
|
||||
Map<String, String> map1 = new HashMap<String, String>();
|
||||
Range[] range = sheet.getMergedCells();
|
||||
for (int i = 0; i < range.length; i++) {
|
||||
Cell topCell = range[i].getTopLeft();
|
||||
Cell bottomCell = range[i].getBottomRight();
|
||||
int topRow = topCell.getRow();
|
||||
int topCol = topCell.getColumn();
|
||||
int bottomRow = bottomCell.getRow();
|
||||
int bottomCol = bottomCell.getColumn();
|
||||
map0.put(topRow + "," + topCol, bottomRow + "," + bottomCol);
|
||||
int tempRow = topRow;
|
||||
while (tempRow <= bottomRow) {
|
||||
int tempCol = topCol;
|
||||
while (tempCol <= bottomCol) {
|
||||
map1.put(tempRow + "," + tempCol, "");
|
||||
tempCol++;
|
||||
}
|
||||
tempRow++;
|
||||
}
|
||||
map1.remove(topRow + "," + topCol);
|
||||
}
|
||||
Map[] map = { map0, map1 };
|
||||
return map;
|
||||
}
|
||||
|
||||
private static String convertToHtmlGrammer(Alignment alignment) {
|
||||
String align = "left";
|
||||
switch (alignment.getValue()) {
|
||||
case 1:
|
||||
align = "left";
|
||||
break;
|
||||
case 2:
|
||||
align = "center";
|
||||
break;
|
||||
case 3:
|
||||
align = "right";
|
||||
break;
|
||||
case 5:
|
||||
align = "justify";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return align;
|
||||
}
|
||||
|
||||
private static String convertToHtmlGrammer(VerticalAlignment verticalAlignment) {
|
||||
String valign = "middle";
|
||||
switch (verticalAlignment.getValue()) {
|
||||
case 1:
|
||||
valign = "middle";
|
||||
break;
|
||||
case 2:
|
||||
valign = "bottom";
|
||||
break;
|
||||
case 3:
|
||||
valign = "top";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return valign;
|
||||
}
|
||||
|
||||
/*private static String convertToHtmlGrammer(Colour colour) {
|
||||
StringBuffer sb = new StringBuffer("");
|
||||
if (colour != null && !"default background".equalsIgnoreCase(colour.getDescription())) {
|
||||
sb.append("#");
|
||||
sb.append(fillWithZero(Integer.toHexString(colour.getDefaultRGB().getRed())));
|
||||
sb.append(fillWithZero(Integer.toHexString(colour.getDefaultRGB().getGreen())));
|
||||
sb.append(fillWithZero(Integer.toHexString(colour.getDefaultRGB().getBlue())));
|
||||
}
|
||||
return sb.toString();
|
||||
}*/
|
||||
|
||||
private static String fillWithZero(String str) {
|
||||
if (str != null && str.length() < 2) {
|
||||
return "0" + str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
import com.raqsoft.dm.Sequence;
|
||||
import com.raqsoft.report.model.ReportDefine;
|
||||
import com.raqsoft.report.usermodel.Context;
|
||||
import com.raqsoft.report.usermodel.DataSourceConfig;
|
||||
import com.raqsoft.report.usermodel.Engine;
|
||||
import com.raqsoft.report.usermodel.IReport;
|
||||
import com.raqsoft.report.util.ReportUtils;
|
||||
import com.raqsoft.report.util.StyleConfig;
|
||||
import com.raqsoft.report.view.ReportExporter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) throws Throwable {
|
||||
// 设置报表授权文件
|
||||
File flic = new File("./reportTrialLicense20211231.xml");
|
||||
FileInputStream lis = new FileInputStream(flic);
|
||||
Sequence.readLicense(Sequence.P_RPT, lis);
|
||||
|
||||
//加载报表
|
||||
String reportFile = "D:\\1.rpx"; //该文件名可以为绝对路径,也可以相对当前程序启动路径
|
||||
ReportDefine rd = (ReportDefine) ReportUtils.read(reportFile);
|
||||
|
||||
//构建报表引擎计算环境
|
||||
Context cxt = new Context();
|
||||
Connection con = null;
|
||||
try {
|
||||
Driver driver = (Driver) Class.forName("org.postgresql.Driver").newInstance();
|
||||
DriverManager.registerDriver(driver);
|
||||
con = DriverManager.getConnection("jdbc:postgresql://10.10.14.206:5432/eduData_db", "root", "DsideaL147258369");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
cxt.setConnection("HUANGHAI", con);
|
||||
cxt.setDefDataSourceName("HUANGHAI");//这样设定默认数据源
|
||||
Engine engine = new Engine(rd, cxt); //构造报表引擎
|
||||
|
||||
IReport iReport = engine.calc(); //运算报表
|
||||
ReportExporter re = new ReportExporter("d:\\1.xls", ReportExporter.EXPORT_EXCEL); //导出为Excel
|
||||
re.export(iReport); //导出
|
||||
|
||||
System.out.println("恭喜,导出成功!");
|
||||
}
|
||||
}
|
Loading…
Reference in new issue