здравствуйте спецы, помогите разобраться с выборкой определенного значения из коллекции и сравнением этого значения с полем в эксельшите Использовал библеотеку JXL для экселя. Также мы используем библеотеки DFC (documentum foundation classes) над стройка над JAVA API для работы с документообротом, из библеотеки DFC я использовал выборку из БД Вопрос: Как значение из коллекции (select запрос из БД) сравнить с данными в эксель шите? Смотрите фрагмет в коде: //как реализовать логику которое описано в начале- если кто думает по другому, буду рад выслушать рекомендации if (<value_from_callection>.equals(sheet.getCell(j,i).getContents())) {.......... <value_from_callection> - не заню как реализовать вот код: | Код | import java.awt.Color; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.HashSet;
import com.documentum.com.DfClientX; import com.documentum.com.IDfClientX; import com.documentum.fc.client.IDfClient; import com.documentum.fc.client.IDfCollection; import com.documentum.fc.client.IDfQuery; import com.documentum.fc.client.IDfSession; import com.documentum.fc.client.IDfSessionManager; import com.documentum.fc.common.DfException; import com.documentum.fc.common.IDfLoginInfo; import com.documentum.fc.common.IDfValue;
import jxl.Cell; import jxl.CellType; import jxl.CellView; import jxl.Sheet; import jxl.Workbook; import jxl.format.UnderlineStyle; import jxl.read.biff.BiffException; import jxl.write.Label; import jxl.write.WritableCellFormat; import jxl.write.WritableFont; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException; import jxl.write.biff.RowsExceededException;
public class test_JXL_b { public IDfClientX clientx; public IDfSession session; public IDfSessionManager sMgr; public IDfClient client; private WritableCellFormat timesBoldUnderline; private WritableCellFormat times; private String inputFile;
Workbook w; public void setInputFile(String inputFile) { this.inputFile = inputFile; } public void read() throws Exception { File inputWorkbook = new File(inputFile); try { w = Workbook.getWorkbook(inputWorkbook); Sheet sheet = w.getSheet(0); WritableWorkbook workbook = Workbook.createWorkbook(new File("C:/BU/BU_Test/BMHJ_Test/test/1.xls")); WritableSheet sheet1 = workbook.createSheet("First Sheet", 0); Label label_doc_status_valid = new Label(0, 0, "Document Status"); sheet1.addCell(label_doc_status_valid); Label label_import_info = new Label(1, 0, "Import Information"); sheet1.addCell(label_import_info); Label label_import_docid = new Label(2, 0, "Import Doc.ID"); sheet1.addCell(label_import_docid); for (int i = 0; i < sheet.getRows(); i++) { String str=""; for (int j = 0; j < sheet.getColumns(); j++) { str= str+" "+sheet.getCell(j,i).getContents(); Label label = new Label(j+3, i, sheet.getCell(j,i).getContents()); sheet1.addCell(label); //if any cell in pointed Header cells has errors -then do validation if (sheet.getCell(j,0).getContents().equals("Asset") | sheet.getCell(j,0).getContents().equals("Originator") | sheet.getCell(j,0).getContents().equals("Discipline Type") | sheet.getCell(j,0).getContents().equals("Discipline Category") | sheet.getCell(j,0).getContents().equals("Document Type") | sheet.getCell(j,0).getContents().equals("Confidentiality")) { if (i!=0) { validation(j,i); } } //System.out.println(str); } } workbook.write(); workbook.close(); } catch (BiffException e) { e.printStackTrace(); } }
public void validation(int j, int i) throws Exception{ sMgr = createSessionManager(); session = sMgr.getSession("EDMS_TRN_AT"); IDfCollection myColl = null; Sheet sheet = w.getSheet(0); //retrieving name from picklist item - select Name from picklist table where Name = 'Cell_Value'; String myQuery = "select distinct object_name from cs_picklist_item where object_name ='" + sheet.getCell(j,i).getContents() + "'"; myColl = execQuery ( session , myQuery ); //displayResults1(myColl); //как реализовать логику которое описано в начале- если кто думает по другому, буду рад выслушать рекомендации if (<value_from_callection>.equals(sheet.getCell(j,i).getContents())) { Label label_doc_status_valid = new Label(0, i, "VALID"); //((WritableSheet) sheet).addCell(label_doc_status_valid); System.out.println("VALID"); } else { Label label_doc_status_valid = new Label(0, i, "INVALID"); //((WritableSheet) sheet).addCell(label_doc_status_valid); System.out.println("INVALID"); } }
public static void displayResults1(IDfCollection col) throws DfException, IOException { while (col.next()) { String str = (col.getValue("object_name") +"\n"); System.out.print(str); } } public static IDfCollection execQuery(IDfSession sess, String queryString) throws DfException, IOException { IDfCollection col = null; IDfClientX myClientx = new DfClientX(); IDfQuery q = myClientx.getQuery(); q.setDQL(queryString); col = q.execute(sess, 0); return col; } public static void main(String[] args) throws Exception { test_JXL_b test = new test_JXL_b(); test.setInputFile("C:/BU/BU_Test/BMHJ_Test/AttrSheet_Control_fgD_for_NewDoc.xls"); test.read(); System.out.println("Please check"); } IDfSessionManager createSessionManager() throws Exception { clientx = new DfClientX(); IDfLoginInfo loginInfoObj = clientx.getLoginInfo(); loginInfoObj.setDomain(""); loginInfoObj.setUser("install_owner"); loginInfoObj.setPassword("xxx"); client = clientx.getLocalClient(); sMgr = client.newSessionManager(); sMgr.setIdentity("EDMS_TRN_AT", loginInfoObj); return sMgr; } }
|
|