List of usage examples for org.apache.poi.hssf.usermodel HSSFRow getLastCellNum
@Override public short getLastCellNum()
From source file:com.xhsoft.framework.common.file.ExcelHandle.java
License:Open Source License
/** * ????.xls//from w w w . j av a 2 s. c om * @params {:,:} * @return void * @author lijiangwei * @since 2012-11-12 */ private void readXLS() { for (int sheetNum = 0; sheetNum < xls.getNumberOfSheets(); sheetNum++) { HSSFSheet xls_sheet = xls.getSheetAt(sheetNum); if (xls_sheet == null) { continue; } // ??Sheet for (int rowNum = 0; rowNum <= xls_sheet.getLastRowNum(); rowNum++) { HSSFRow xls_row = xls_sheet.getRow(rowNum); if (xls_row == null) { continue; } // ???? for (int cellNum = 0; cellNum < xls_row.getLastCellNum(); cellNum++) { HSSFCell xls_cell = xls_row.getCell(cellNum); if (xls_cell == null) { continue; } System.out.print(" " + getCellValue(xls_cell)); } System.out.println(); } } }
From source file:com.xpn.xwiki.plugin.lucene.textextraction.MSExcelTextExtractor.java
License:Open Source License
/** * It will parse row and return the text */// w ww . j ava 2 s .c o m private void parseRow(HSSFRow row, StringBuffer cleanBuffer) { short firstCell = row.getFirstCellNum(); short lastCell = row.getLastCellNum(); for (short cellIdx = firstCell; cellIdx <= lastCell; cellIdx++) { HSSFCell cell = row.getCell(cellIdx); if (cell != null) { parseCell(cell, cleanBuffer); } } }
From source file:com.xx.platform.util.tools.ms.ExcelExtractor.java
License:Apache License
public String extractText(POIFSFileSystem poifs) throws Exception { StringBuffer resultText = new StringBuffer(); HSSFWorkbook wb = new HSSFWorkbook(poifs, true); if (wb == null) { return ""; }//from ww w . ja v a2 s. c om HSSFSheet sheet; HSSFRow row; HSSFCell cell; int sNum = 0; int rNum = 0; int cNum = 0; sNum = wb.getNumberOfSheets(); for (int i = 0; i < sNum; i++) { if ((sheet = wb.getSheetAt(i)) == null) { continue; } rNum = sheet.getLastRowNum(); for (int j = 0; j <= rNum; j++) { if ((row = sheet.getRow(j)) == null) { continue; } cNum = row.getLastCellNum(); for (int k = 0; k < cNum; k++) { if ((cell = row.getCell((short) k)) != null) { /*if(HSSFDateUtil.isCellDateFormatted(cell) == true) { resultText += cell.getDateCellValue().toString() + " "; } else */ if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { resultText.append(cell.getStringCellValue()); } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { Double d = new Double(cell.getNumericCellValue()); resultText.append(d.toString()); } /* else if(cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA){ resultText += cell.getCellFormula() + " "; } */ } } } } return resultText.toString(); }
From source file:com.xx.platform.util.tools.ms.ExcelExtrator.java
License:Apache License
public String extractText(POIFSFileSystem poifs) throws Exception { List<Map<String, String>> list = new ArrayList<Map<String, String>>(); String text = null;//from www . j a va 2 s. c o m try { HSSFWorkbook wb = new HSSFWorkbook(poifs, true); if (wb == null) { return null; } HSSFSheet sheet; HSSFRow row; HSSFCell cell; int sNum = 0; int rNum = 0; int cNum = 0; sNum = wb.getNumberOfSheets(); for (int i = 0; i < sNum; i++) { if ((sheet = wb.getSheetAt(i)) == null) { continue; } String[] key = null; //field boolean init = false; //key rNum = sheet.getLastRowNum(); for (int j = 0; j <= rNum; j++) { if ((row = sheet.getRow(j)) == null) { continue; } Map<String, String> rowdata = new HashMap<String, String>(); cNum = row.getLastCellNum(); if (!init) key = new String[cNum]; String value = ""; StringBuffer content = new StringBuffer(); for (int k = 0; k < cNum; k++) { if ((cell = row.getCell((short) k)) != null) { if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) { value = cell.getStringCellValue(); } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { Double d = new Double(cell.getNumericCellValue()); value = d.toString(); } else value = ""; if (init) { content.append(value); } else { key[k] = value; } } } } } } catch (Exception e) { text = ""; } return text; }
From source file:com.yyl.common.utils.excel.ExcelTools.java
private static List<List<Object>> readXLSWithHeader(InputStream inputStream) throws IOException { // InputStream is = new FileInputStream(file); HSSFWorkbook wb = new HSSFWorkbook(inputStream); HSSFSheet sheet = wb.getSheetAt(0);// w ww . j a v a 2s . c o m List<List<Object>> o = new ArrayList(); List<Object> temp = null; if (sheet == null) { return null; } for (int row_index = 0; row_index <= sheet.getLastRowNum(); row_index++) { HSSFRow row = sheet.getRow(row_index); if (row == null) { continue; } temp = new ArrayList(); for (int col_index = 0; col_index <= row.getLastCellNum(); col_index++) { temp.add(getCellValue(row.getCell(col_index))); } o.add(temp); } return o; }
From source file:com.yyl.common.utils.excel.ExcelTools.java
private static List<List<Object>> readXLS(InputStream inputStream) throws IOException { // InputStream is = new FileInputStream(file); HSSFWorkbook wb = new HSSFWorkbook(inputStream); HSSFSheet sheet = wb.getSheetAt(0);//from ww w .ja va 2 s . co m List<List<Object>> o = new ArrayList(); List<Object> temp = null; if (sheet == null) { return null; } for (int row_index = 1; row_index <= sheet.getLastRowNum(); row_index++) { HSSFRow row = sheet.getRow(row_index); if (row == null) { continue; } temp = new ArrayList(); for (int col_index = 0; col_index <= row.getLastCellNum(); col_index++) { temp.add(getCellValue(row.getCell(col_index))); } o.add(temp); } return o; }
From source file:com.zhu.action.CarAction.java
public void exportpeople(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {/* w w w.j a v a2s .c o m*/ CarForm carForm = (CarForm) form; // webbookExcel HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet("?"); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); // ? HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFCell cell = row.createCell(0); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell(1); cell.setCellValue("???"); cell.setCellStyle(style); // ? ?? OrderService orderService = new OrderService(); List<Orderinfo> list = orderService.getOrderCarDetail(carForm.getId()); System.out.println(list.size()); for (int i = 0; i < list.size(); i++) { row = sheet.createRow(i + 1); Orderinfo order = (Orderinfo) list.get(i); // ? row.createCell(0).setCellValue(order.getN1()); row.createCell(1).setCellValue(order.getI1()); row = sheet.createRow(i + list.size() + 1); row.createCell(0).setCellValue(order.getN2()); row.createCell(1).setCellValue(order.getI2()); row = sheet.createRow(i + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN3()); row.createCell(1).setCellValue(order.getI3()); row = sheet.createRow(i + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN4()); row.createCell(1).setCellValue(order.getI4()); row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN5()); row.createCell(1).setCellValue(order.getI5()); row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN6()); row.createCell(1).setCellValue(order.getI6()); row = sheet.createRow( i + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN7()); row.createCell(1).setCellValue(order.getI7()); row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN8()); row.createCell(1).setCellValue(order.getI8()); row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN9()); row.createCell(1).setCellValue(order.getI9()); row = sheet.createRow(i + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + list.size() + 1); row.createCell(0).setCellValue(order.getN10()); row.createCell(1).setCellValue(order.getI10()); } // ? String filePath = ""; Date dt = new Date(); DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String date = df.format(dt).toString(); filePath = "/Users/Nemo/Documents/carpeople" + date + ".xls"; File file = new File(filePath); try { // FileOutputStream fout = new FileOutputStream( // "/Users/Nemo/Documents/carpeople.xls"); // wb.write(fout); // fout.close(); OutputStream out = new FileOutputStream(file); wb.write(out); out.close(); } catch (Exception e) { e.printStackTrace(); } int key = 0; int MaxRowNum = 0, MaxCellNum = 0; try { FileInputStream in = new FileInputStream(filePath); POIFSFileSystem fs = new POIFSFileSystem(in); HSSFWorkbook workbook = new HSSFWorkbook(fs); FileOutputStream out = new FileOutputStream("/Users/Nemo/Documents/carpeople" + date + ".xls"); int number = workbook.getNumberOfSheets(); for (int i = 0; i < number; i++) { // ?sheet sheet = workbook.getSheetAt(i); // 14 System.out.println("" + sheet.getSheetName() + " ? " + (sheet.getLastRowNum() + 1)); MaxRowNum = 0; for (int k = 0; k <= sheet.getLastRowNum(); k++) { HSSFRow hRow = sheet.getRow(k); // System.out.println((k + 1) + ""); if (isBlankRow(hRow)) // { int m = 0; for (m = k + 1; m <= sheet.getLastRowNum(); m++) { HSSFRow nhRow = sheet.getRow(m); if (!isBlankRow(nhRow)) { // System.out.println("?" + (m + 1)); sheet.shiftRows(m, sheet.getLastRowNum(), k - m); break; } } if (m > sheet.getLastRowNum()) break; // ? } else { // ? MaxRowNum++; if (MaxCellNum < hRow.getLastCellNum()) MaxCellNum = hRow.getLastCellNum(); } } workbook.setPrintArea(i, 0, MaxCellNum, 0, MaxRowNum); System.out .println("?? " + sheet.getSheetName() + " " + MaxRowNum); } workbook.write(out); in.close(); out.close(); } catch (IOException e) { System.out.println(key + " " + e.getMessage() + " "); e.printStackTrace(); } System.out.println("??"); }
From source file:com.zhu.action.CarAction.java
/** * excel /*from w w w . jav a 2s . c om*/ */ public boolean isBlankRow(HSSFRow row) { if (row == null) return true; for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { HSSFCell hcell = row.getCell(i); if (!isBlankCell(hcell)) return false; } return true; }
From source file:com.zxy.commons.poi.excel.ExcelUtils.java
License:Apache License
/** * ?Excelsheet/*from w ww. ja va 2 s . c om*/ * * @param inputPath ???Excel * @return Excel? * @throws IOException IOException */ public static Map<String, Table<Integer, String, String>> readAll2table(String inputPath) throws IOException { Map<String, Table<Integer, String, String>> tables = Maps.newLinkedHashMap(); FileInputStream inputStream = null; HSSFWorkbook wb = null; try { inputStream = new FileInputStream(inputPath); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); // HSSFWorkbook POIFSFileSystem fs = new POIFSFileSystem(bufferedInputStream); wb = new HSSFWorkbook(fs); List<String> columnNames = Lists.newLinkedList(); for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) { Table<Integer, String, String> table = TreeBasedTable.create(); HSSFSheet st = wb.getSheetAt(sheetIndex); String sheetName = st.getSheetName(); for (int rowIndex = 0; rowIndex <= st.getLastRowNum(); rowIndex++) { HSSFRow row = st.getRow(rowIndex); for (int columnIndex = 0; columnIndex < row.getLastCellNum(); columnIndex++) { HSSFCell cell = row.getCell(columnIndex); if (cell != null) { if (rowIndex == 0) { // columnNames.add(cell.getStringCellValue()); } else { String value = cell.getStringCellValue(); table.put(rowIndex, columnNames.get(columnIndex), value); } } } } tables.put(sheetName, table); } return tables; } finally { if (wb != null) { wb.close(); } if (inputStream != null) { inputStream.close(); } } }
From source file:de.bund.bfr.knime.openkrise.db.imports.GeneralXLSImporter.java
License:Open Source License
public boolean doImport(final String filename, final JProgressBar progress, final boolean showResults) { Runnable runnable = new Runnable() { public void run() { try { if (progress != null) { progress.setVisible(true); progress.setStringPainted(true); progress.setString("Importiere Excel Datei..."); progress.setMinimum(0); }//from w ww . java2 s .co m InputStream is = null; System.out.println(filename); if (filename.startsWith("http://")) { URL url = new URL(filename); URLConnection uc = url.openConnection(); is = uc.getInputStream(); } else if (filename.startsWith("/de/bund/bfr/knime/openkrise/db/res/")) { is = this.getClass().getResourceAsStream(filename); } else { is = new FileInputStream(filename); } try (HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(is))) { HSSFSheet sheet; HSSFRow row; int numSuccess = 0; int numFailed = 0; String unusedFields = ""; for (int i = 0; i < wb.getNumberOfSheets(); i++) { sheet = wb.getSheetAt(i); String tableName = sheet.getSheetName(); MyTable myT = DBKernel.myDBi.getTable(tableName); if (myT != null) { int numRows = sheet.getLastRowNum(); if (progress != null) { progress.setMaximum(numRows); progress.setValue(0); } row = sheet.getRow(0); String sql1 = ""; String sql2 = ""; String sql3 = ""; Vector<String> codeSql1 = new Vector<>(); Vector<String> codeSql2 = new Vector<>(); LinkedHashMap<MyTable, Vector<Integer>> foreignTables = new LinkedHashMap<>(); int numCols = row.getLastCellNum(); String[] fieldNames = new String[numCols]; String[] fieldTypes = new String[numCols];//getTypes(fieldNames, myT); String[] ffieldTypes = new String[numCols]; MyTable[] myForeignTables = new MyTable[numCols]; String[] kzS = new String[numCols]; String[] dbFieldnames = new String[numCols]; int lfdCol = 0; Hashtable<String, String> dbFieldNames = new Hashtable<>(); for (int j = 0; j < numCols; j++) { String fieldName = row.getCell(j).getStringCellValue(); fieldNames[j] = fieldName; int ffe; String dbFieldName = getDBFieldName(fieldName, myT, takecareofID); if (dbFieldName != null) { String ft = getForeignTable(dbFieldName, myT); if (ft != null && ft.equals("DoubleKennzahlen")) { kzS[j] = getKZ(fieldName, dbFieldName); dbFieldnames[j] = dbFieldName; } else if (!dbFieldNames.containsKey(dbFieldName)) { dbFieldNames.put(dbFieldName, dbFieldName); sql1 += DBKernel.delimitL(dbFieldName) + ","; sql2 += "?,"; sql3 += DBKernel.delimitL(dbFieldName) + "=?,"; lfdCol++; } fieldTypes[j] = getType(dbFieldName, myT, takecareofID); } else if ((ffe = foreignFieldExists(fieldName, myT)) >= 0) { if (!foreignTables.containsKey(myT.getForeignFields()[ffe])) foreignTables.put(myT.getForeignFields()[ffe], new Vector<Integer>()); ffieldTypes[j] = getType(fieldName, myT.getForeignFields()[ffe], false); foreignTables.get(myT.getForeignFields()[ffe]).add(j); myForeignTables[j] = myT.getForeignFields()[ffe]; } else if (DBKernel.showHierarchic(tableName) && fieldName.toLowerCase().endsWith("-code")) { codeSql1.add(DBKernel.delimitL("CodeSystem") + "," + DBKernel.delimitL("Code") + "," + DBKernel.delimitL("Basis")); codeSql2.add( "'" + fieldName.substring(0, fieldName.length() - "-code".length()) + "',?,?"); } else if (!fieldName.equalsIgnoreCase("id")) { unusedFields += "," + fieldName; } } if (sql1.length() > 0 && sql2.length() > 0) { String sql = "INSERT INTO " + DBKernel.delimitL(tableName) + " (" + sql1.substring(0, sql1.length() - 1) + ") VALUES (" + sql2.substring(0, sql2.length() - 1) + ")"; PreparedStatement ps = DBKernel.getDBConnection().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); int idCol = lfdCol + 1; sql = "UPDATE " + DBKernel.delimitL(tableName) + " SET " + sql3.substring(0, sql3.length() - 1) + " WHERE " + DBKernel.delimitL("ID") + "=?"; PreparedStatement psUpdate = DBKernel.getDBConnection().prepareStatement(sql); PreparedStatement[] psCodes = new PreparedStatement[codeSql1.size()]; boolean doCode[] = new boolean[codeSql1.size()]; int codesI; for (codesI = 0; codesI < codeSql1.size(); codesI++) { sql = "INSERT INTO " + DBKernel.delimitL(DBKernel.getCodesName(tableName)) + " (" + codeSql1.get(codesI) + ") VALUES (" + codeSql2.get(codesI) + ")"; psCodes[codesI] = DBKernel.getDBConnection().prepareStatement(sql); } LinkedHashMap<MyTable, PreparedStatement> psForeign = new LinkedHashMap<>(); LinkedHashMap<MyTable, PreparedStatement> psForeignUpdate = new LinkedHashMap<>(); for (Map.Entry<MyTable, Vector<Integer>> entry : foreignTables.entrySet()) { Vector<Integer> vs = entry.getValue(); String ssql1 = "", ssql2 = "", ssql3 = ""; for (int ii = 0; ii < vs.size(); ii++) { ssql1 += "," + DBKernel.delimitL(fieldNames[vs.get(ii)]); ssql2 += ",?"; ssql3 += "," + DBKernel.delimitL(fieldNames[vs.get(ii)]) + "=?"; } if (ssql1.length() > 0 && ssql2.length() > 0 && ssql3.length() > 0) { sql = "INSERT INTO " + DBKernel.delimitL(entry.getKey().getTablename()) + " (" + ssql1.substring(1) + ") VALUES (" + ssql2.substring(1) + ")"; psForeign.put(entry.getKey(), DBKernel.getDBConnection() .prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)); sql = "UPDATE " + DBKernel.delimitL(entry.getKey().getTablename()) + " SET " + ssql3.substring(1) + " WHERE " + DBKernel.delimitL("ID") + "=?"; psForeignUpdate.put(entry.getKey(), DBKernel.getDBConnection().prepareStatement(sql)); } } LinkedHashMap<Object, String> hashBL = null; Iterator<Row> rows = sheet.rowIterator(); int lfd = 0; while (rows.hasNext()) { row = (HSSFRow) rows.next(); boolean setID = false; Integer lastID = null; ps.clearParameters(); psUpdate.clearParameters(); for (codesI = 0; codesI < codeSql1.size(); codesI++) { psCodes[codesI].clearParameters(); doCode[codesI] = false; } LinkedHashMap<MyTable, Integer> lfdColsForeign = new LinkedHashMap<>(); for (Map.Entry<MyTable, PreparedStatement> entry : psForeignUpdate .entrySet()) { MyTable myT1 = entry.getKey(); psForeign.get(myT1).clearParameters(); psForeignUpdate.get(myT1).clearParameters(); lfdColsForeign.put(myT1, 0); } if (row.getRowNum() > 0) { lfdCol = 0; codesI = 0; Object[] kzVal = new Object[numCols]; for (int j = 0; j < numCols; j++) { if (fieldTypes[j] != null) { /* * if (fieldNames[j].equals( * "Bundesland")) { hashBL = * DBKernel * .myDBi.getHashMap("County"); * } else { hashBL = null; } */ lfdCol++; if (fieldTypes[j].startsWith("VARCHAR(") || fieldTypes[j].startsWith("CHAR(") || fieldTypes[j].startsWith("BLOB(") && !tableName.equals("DateiSpeicher")) manageString(ps, psUpdate, lfdCol, row.getCell(j), hashBL); else if (fieldTypes[j].equals("BOOLEAN")) manageBoolean(ps, psUpdate, lfdCol, row.getCell(j)); else if (fieldTypes[j].equals("INTEGER")) manageInteger(ps, psUpdate, lfdCol, row.getCell(j)); else if (fieldTypes[j].equals("BIGINT")) manageBigInteger(ps, psUpdate, lfdCol, row.getCell(j)); else if (fieldTypes[j].equals("DATE")) manageDate(ps, psUpdate, lfdCol, row.getCell(j)); else if (fieldTypes[j].equals("DOUBLE")) { if (kzS[j] != null) { lfdCol--; //System.err.println(dbFieldnames[j] + "\t" + kzS[j]); if (DBKernel.kzIsString(kzS[j])) kzVal[j] = manageString(null, null, lfdCol, row.getCell(j)); else if (DBKernel.kzIsBoolean(kzS[j])) kzVal[j] = manageBoolean(null, null, lfdCol, row.getCell(j)); else kzVal[j] = manageDouble(null, null, lfdCol, row.getCell(j)); } else { manageDouble(ps, psUpdate, lfdCol, row.getCell(j)); } } else System.err.println( "Wasn hier los? Undefinierter Feldtyp???? ->\t" + fieldNames[j]); } else if (myForeignTables[j] != null && ffieldTypes[j] != null) { lfdColsForeign.put(myForeignTables[j], lfdColsForeign.get(myForeignTables[j]) + 1); if (ffieldTypes[j].startsWith("VARCHAR(") || ffieldTypes[j].startsWith("CHAR(") || ffieldTypes[j].startsWith("BLOB(") && !tableName.equals("DateiSpeicher")) manageString(psForeign.get(myForeignTables[j]), psForeignUpdate.get(myForeignTables[j]), lfdColsForeign.get(myForeignTables[j]), row.getCell(j), hashBL); else if (ffieldTypes[j].equals("BOOLEAN")) manageBoolean(psForeign.get(myForeignTables[j]), psForeignUpdate.get(myForeignTables[j]), lfdColsForeign.get(myForeignTables[j]), row.getCell(j)); else if (ffieldTypes[j].equals("INTEGER")) manageInteger(psForeign.get(myForeignTables[j]), psForeignUpdate.get(myForeignTables[j]), lfdColsForeign.get(myForeignTables[j]), row.getCell(j)); else if (ffieldTypes[j].equals("BIGINT")) manageBigInteger(psForeign.get(myForeignTables[j]), psForeignUpdate.get(myForeignTables[j]), lfdColsForeign.get(myForeignTables[j]), row.getCell(j)); else if (fieldTypes[j].equals("DATE")) manageDate(psForeign.get(myForeignTables[j]), psForeignUpdate.get(myForeignTables[j]), lfdColsForeign.get(myForeignTables[j]), row.getCell(j)); else if (ffieldTypes[j].equals("DOUBLE")) { manageDouble(psForeign.get(myForeignTables[j]), psForeignUpdate.get(myForeignTables[j]), lfdColsForeign.get(myForeignTables[j]), row.getCell(j)); } else System.err.println(fieldNames[j] + " Feldtype????"); } else if (fieldNames[j].equals("ID")) { lastID = manageInteger(null, null, 0, row.getCell(j)); if (lastID != null) { if (DBKernel.hasID(tableName, lastID.intValue())) { psUpdate.setInt(idCol, lastID.intValue()); setID = true; } } } else if (DBKernel.showHierarchic(tableName) && fieldNames[j].toLowerCase().endsWith("-code")) { String code = manageString(psCodes[codesI], null, 1, row.getCell(j)); if (code != null && code.length() > 0) doCode[codesI] = true; codesI++; } else { //System.out.println(fieldNames[j]); } } try { if (setID) { psUpdate.execute(); } else { if (ps.executeUpdate() > 0) {// execute() lastID = DBKernel.getLastInsertedID(ps); } else { System.err.println("W"); } } numSuccess++; if (lastID != null) { for (int j = 0; j < numCols; j++) { if (dbFieldnames[j] != null && kzVal[j] != null) { DBKernel.insertDBL(myT.getTablename(), dbFieldnames[j], lastID, null, kzS[j], kzVal[j]); } } for (codesI = 0; codesI < codeSql1.size(); codesI++) { if (doCode[codesI]) { psCodes[codesI].setInt(2, lastID); try { psCodes[codesI].execute(); numSuccess++; } catch (SQLException e1) { numFailed++; System.err.println(psCodes[codesI]); } } } for (Map.Entry<MyTable, PreparedStatement> entry : psForeign .entrySet()) { MyTable myT1 = entry.getKey(); MyTable[] foreignTs = myT.getForeignFields(); for (int ii = 0; ii < foreignTs.length; ii++) { if (foreignTs[ii] != null && foreignTs[ii].equals(myT1)) { if (psForeign.get(myT1).executeUpdate() > 0) { // INSERT int lID = DBKernel .getLastInsertedID(psForeign.get(myT1)); // Das erstbeste Feld, das auf den Fremdtable verweist, wird mit dem Neueintrag verlinkt DBKernel.sendRequest("UPDATE " + DBKernel.delimitL(tableName) + " SET " + DBKernel.delimitL( myT.getFieldNames()[ii]) + "=" + lID + " WHERE " + DBKernel.delimitL("ID") + "=" + lastID, false); } break; } } } /* * for (int j=0;j<numCols;j++) { * if (myForeignTables[j] != * null && ffieldTypes[j] != * null) { MyTable[] foreignTs = * myT.getForeignFields(); for * (int * ii=0;ii<foreignTs.length; * ii++) { if (foreignTs[ii] != * null && foreignTs[ii].equals( * myForeignTables[j])) { if * (psForeign * .get(myForeignTables * [j]).executeUpdate() > 0) { * // INSERT int lID = * DBKernel.getLastInsertedID * (psForeign * .get(myForeignTables[j])); * DBKernel * .sendRequest("UPDATE " + * DBKernel.delimitL(tableName) * + " SET " + * DBKernel.delimitL( * myT.getFieldNames()[ii]) + * "=" + lID + " WHERE " + * DBKernel.delimitL("ID") + "=" * + lastID, false); } break; } * } } } */ } } catch (Exception e1) { numFailed++; MyLogger.handleMessage(ps.toString()); MyLogger.handleException(e1); } } if (progress != null) { lfd++; progress.setValue(lfd); } } } myT.doMNs(); if (progress != null) { // Refreshen: MyDBTable myDB = DBKernel.mainFrame.getMyList().getMyDBTable(); if (myDB.getActualTable() != null) { String actTablename = myDB.getActualTable().getTablename(); if (actTablename.equals(tableName) || actTablename.equals(DBKernel.getCodesName(tableName))) { myDB.setTable(myDB.getActualTable()); } } MyDBTree myTR = DBKernel.mainFrame.getMyList().getMyDBTree(); if (myTR.getActualTable() != null) { String actTablename = myTR.getActualTable().getTablename(); if (actTablename.equals(tableName) || actTablename.equals(DBKernel.getCodesName(tableName))) { myTR.setTable(myTR.getActualTable()); } } } } else { System.err.println(tableName + " nicht in DB???"); } } if (progress != null) { progress.setVisible(false); } String log = numSuccess + " erfolgreiche Importe.\n"; log += numFailed + " fehlgeschlagene Importe.\n"; if (unusedFields.length() > 0) log += "Unbekannte Felder: " + unusedFields.substring(1) + "\n"; if (showResults) { InfoBox ib = new InfoBox(log, true, new Dimension(400, 300), null); ib.setVisible(true); } else { System.out.println("GeneralXLSImporter (" + filename + "):\n" + log); } } catch (Exception e) { MyLogger.handleException(e); } } catch (Exception e) { MyLogger.handleException(e); } } }; Thread thread = new Thread(runnable); thread.start(); try { thread.join(); } catch (InterruptedException e) { MyLogger.handleException(e); } return true; }