62,614
社区成员
发帖
与我相关
我的任务
分享
private String[] columnNames = {"名称", "页数"};
private Object[][] data = {
{"KathySmithSnowboarding", new Integer(5)},
{"DoGFGFhnDoeRowing", new Integer(0)},
{"TUHJohnDoeRowing", new Integer(7)},
{"OPKJJohnDoeRowing", new Integer(0)},}
private void TranceData() {
int RowsCount = 0, numRows = tb.getRowCount(),numCols=tb.getColumnCount();
Object tmp[][] = new Object[numRows][numCols];
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
tmp[i][j] = tb.getValueAt(i, j);
System.out.print("|"+tmp[i][j]);
}
}
for (int i = 0; i < numRows; i++) {
if (tb.getValueAt(i, 1) != "0") {
RowsCount++;
}
}
Object[] objs = new Object[RowsCount];
for (int j = 0; j < RowsCount; j++) {
Map maps = new HashMap();
maps.put("内容", );
maps.put("页数", );
objs[j] = maps;
}
private void TranceData() throws JRException {
JasperReport jasperReport;
JasperPrint jasperPrint;
int RowsCount = 0, numRows = tb.getRowCount(),numCols=tb.getColumnCount();
Object tmp[][] = new Object[numRows][numCols];
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
tmp[i][j] = tb.getValueAt(i, j);
//System.out.print("");//("|"+tmp[i][j]);
}
}
//System.out.print(tmp.getClass());
for (int i = 0; i < numRows; i++) {
if (tb.getValueAt(i, 1) != "0") {
RowsCount++;
}
}
//System.out.println(RowsCount+""+tb.getValueAt(1, 1).getClass());
Object forMap[][]=new Object[numRows][numCols];
int ci=0,cj=0;
while(cj<RowsCount)
{
if (tmp[ci][1]!="0"){
forMap[cj][0]=tmp[ci][0];
forMap[cj][1]=tmp[ci][1];
cj++;
}
ci++;
}
//debug
if(false){
// System.out.println(forMap.length);
for (int i = 0; i <RowsCount; i++) {
for (int j = 0; j < numCols; j++) {
System.out.print("fromat|"+forMap[i][j]+"|");
}
}
}
////
// int hi=0;
// while (tmp[hi][1]=="0"){
// for(int i=hi-1;i<tmp.length;i++){
//tmp[i][0]=tmp[i+1][0];
//tmp[i][1]=tmp[i+1][1];
//
// }
// //tmp--;
// }
Object[] objs = new Object[RowsCount];
for (int j = 0; j < RowsCount; j++) {
Map maps = new HashMap();
maps.put("name", forMap[j][0]);
maps.put("address", forMap[j][1]);
objs[j] = maps;
}
JRDataSource dataSource = new JRMapArrayDataSource(objs) {};
jasperReport = JasperCompileManager.compileReport("./reports/report1.jrxml");
jasperPrint = JasperFillManager.fillReport(jasperReport, null, dataSource);
//JasperExportManager.exportReportToPdfFile(jasperPrint, "c://1.pdf");
JasperViewer.viewReport(jasperPrint);