0

Business Objects のフォルダ内のすべてのファイル名を抽出する方法を教えてください。私が今持っているコードを使用して、フォルダー内の単一のファイルの名前を取得できます。そのフォルダ内のすべてのファイル名を取得したい。変数tempには、必要なファイルの名前を入力します。変数docはファイル名を取得する場所であり、変数は外部スプレッドシートに書き込むためreportnameに保存する場所です。doc

public class variable {

    private static String expressionEx;
    private static String nameEx;
    private static String nameXE[] = new String[11];
    private static String expressionXE[] = new String[11];
    private static String query;
    public static String reportName;
    private static String reportPath;



    /** This method writes data to new excel file * */
    public static void writeDataToExcelFile(String fileName) {
        String[][] excelData = preapreDataToWriteToExcel();// Creates first
                                                            // sheet in Excel
        String[][] excelData1 = preapreDataToWriteToExcel1();// Creates
                                                                // second
                                                                // sheet in
                                                                // Excel
        String[][] excelData2 = preapreDataToWriteToExcel2();// Creates third
                                                                // sheet in
                                                                // Excel
        HSSFWorkbook myReports = new HSSFWorkbook();

        HSSFSheet mySheet = myReports.createSheet("Variables");
        HSSFSheet mySheet1 = myReports.createSheet("SQL Statement");
        HSSFSheet mySheet2 = myReports.createSheet("File Info");
        // edits first sheet
        mySheet.setFitToPage(true);
        mySheet.setHorizontallyCenter(true);
        mySheet.setColumnWidth(0, 800 * 6);
        mySheet.setColumnWidth(1, 7000 * 6);
        // edits second sheet
        mySheet1.setFitToPage(true);
        mySheet1.setHorizontallyCenter(true);
        mySheet1.setColumnWidth(0, 800 * 6);
        mySheet1.setColumnWidth(1, 7000 * 6);
        // edits third sheet
        mySheet2.setFitToPage(true);
        mySheet2.setHorizontallyCenter(true);
        mySheet2.setColumnWidth(0, 800 * 6);
        mySheet2.setColumnWidth(1, 2000 * 6);

        HSSFRow myRow = null;
        HSSFCell myCell = null;
        // first sheet
        for (int rowNum = 0; rowNum < excelData[0].length; rowNum++) {
            myRow = mySheet.createRow(rowNum);
            for (int cellNum = 0; cellNum < 4; cellNum++) {
                myCell = myRow.createCell(cellNum);
                myCell.setCellValue(excelData[rowNum][cellNum]);
            }
        }
        try {
            FileOutputStream out = new FileOutputStream(fileName);
            myReports.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // second sheet
        for (int rowNum = 0; rowNum < excelData1[0].length; rowNum++) {
            myRow = mySheet1.createRow(rowNum);
            for (int cellNum = 0; cellNum < 4; cellNum++) {
                myCell = myRow.createCell(cellNum);
                myCell.setCellValue(excelData1[rowNum][cellNum]);
            }
        }
        try {
            FileOutputStream out = new FileOutputStream(fileName);
            myReports.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // third sheet
        for (int rowNum = 0; rowNum < excelData2[0].length; rowNum++) {
            myRow = mySheet2.createRow(rowNum);
            for (int cellNum = 0; cellNum < 4; cellNum++) {
                myCell = myRow.createCell(cellNum);
                myCell.setCellValue(excelData2[rowNum][cellNum]);
            }
        }
        try {
            FileOutputStream out = new FileOutputStream(fileName);
            myReports.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param args
     */
    public static String password;
    public static String username;
    public static String temp;

    public variable() throws FileNotFoundException {
        // TODO Auto-generated method stub

        IEnterpriseSession oEnterpriseSession = null;

        ReportEngines reportEngines = null;
        try {

            // String cmsname = "det0190bpmsdev3";
            // String authenticationType = "secEnterprise";
            String cmsname = "";
            String authenticationType = "";

            // Log in.

            oEnterpriseSession = CrystalEnterprise.getSessionMgr().logon(
                    username, password, cmsname, authenticationType);



            if (oEnterpriseSession == null) {

            } else {

                // Process Document
                reportEngines = (ReportEngines) oEnterpriseSession
                        .getService("ReportEngines");
                ReportEngine wiRepEngine = (ReportEngine) reportEngines
                        .getService(ReportEngines.ReportEngineType.WI_REPORT_ENGINE);

                IInfoStore infoStore = (IInfoStore) oEnterpriseSession
                        .getService("InfoStore");
                String query = "select SI_NAME, SI_ID from CI_INFOOBJECTS "
                        + "where SI_KIND = 'Webi' and SI_INSTANCE=0 and SI_NAME ='"
                        + temp + "'";
                IInfoObjects infoObjects = (IInfoObjects) infoStore
                        .query(query);
                for (Object object : infoObjects) {
                    IInfoObject infoObject = (IInfoObject) object;
                    String path = getInfoObjectPath(infoObject);
                    if (path.startsWith("/")) {
                        DocumentInstance widoc = wiRepEngine
                                .openDocument(infoObject.getID());
                        String doc = infoObject.getTitle();
                    reportPath = path;// this is the path of document
            $$$$$$$$$  reportName = doc;// this is the document name

                        printDocumentVariables(widoc);
                        purgeQueries(widoc);
                        widoc.closeDocument();
                    }
                }
                // End processing
            }
        } catch (SDKException sdkEx) {

        } finally {
            if (reportEngines != null)
                reportEngines.close();
            if (oEnterpriseSession != null)
                oEnterpriseSession.logoff();
        }

    }

    public static void printDocumentVariables(DocumentInstance widoc) {
        int i = 0;
        // this is the report documents variables
        ReportDictionary dic = widoc.getDictionary();
        VariableExpression[] variables = dic.getVariables();

        for (VariableExpression e : variables) {

            nameEx = e.getFormulaLanguageID();
            expressionEx = e.getFormula().getValue();
            // stores variables in array
            nameXE[i] = nameEx;
            expressionXE[i] = expressionEx;

            i++;
        }
    }

    public static String getInfoObjectPath(IInfoObject infoObject)
            throws SDKException {
        String path = "";
        while (infoObject.getParentID() != 0) {
            infoObject = infoObject.getParent();
            path = "/" + infoObject.getTitle() + path;
        }
        return path;
    }

    @SuppressWarnings("deprecation")
    public static void purgeQueries(DocumentInstance widoc) {
        DataProviders dps = widoc.getDataProviders();
        for (int i = 0; i < dps.getCount(); ++i) {
            DataProvider dp = (DataProvider) dps.getItem(i);
            if (dp instanceof SQLDataProvider) {

                SQLDataProvider sdp = (SQLDataProvider) dp;
                sdp.purge(true);
                query = sdp.getQuery().getSQL();
            }
        }
4

1 に答える 1

1

一意のフォルダーTempの名前を保持する場合は、このコードを使用できます。行を次のように置き換えます。String query =

IInfoObjects oParents = infoStore.query("select si_id from ci_infoobjects where si_kind = 'folder' and si_name = '" + temp + "'");
if(oParents.size()==0)
    return; // folder name not found

IInfoObject oParent = (IInfoObject)oParents.get(0);

String query = "select SI_NAME, SI_ID from CI_INFOOBJECTS "
        + "where SI_KIND = 'Webi' and si_parentid = " + oParent.getID();

tempusername、または変数を入力しているコードはわかりませんがpassword、意図的にリストから除外しただけだと思います。明らかに、それらを定義する必要があります。

あなたのコードで気づいた他のいくつかのこと:

  • 各レポートでクエリを消去していますが、後でレポートを保存していません。
  • レポートの SQL を という名前のインスタンス変数に格納していますが、コンストラクターにはquery名前の付いたローカル変数もあります。何かの SQL 値が必要な場合、これにより競合が発生する可能性が非常に高くなります。queryvariable
  • の「空のキャッチ」がありSDKExceptionます。SDKExceptions はあらゆる種類の理由で発生する可能性があり、そのままでは、プログラムが失敗した理由を知ることはできません。少なくとも例外を出力するか、単にバブルアップさせる必要があります。
于 2014-01-15T13:42:40.340 に答える