예제 #1
0
        ///==========================================

        /// main
        static void Main(string[] args)
        {
            // 入力エクセルファイル
            s_srcFile = "src.xlsm";
            // 出力エクセルファイル
            s_destFile          = "dest.xlsx";
            Const.ExtensionName = Utility.GetFileNameExtension(s_srcFile); // extension 置き換え

            SetupCmdArgs(ref s_srcFile, ref s_destFile);

            ExcelApp.GetInstance(); // instance create

            ExcelData ebdata = new ExcelData();
            ExcelData ecdata = new ExcelData();

            LoadFile(
                s_srcFile
                , s_destFile
                , ref ebdata
                , ref ecdata
                );
            log("マージ中 ...");
            MergeSheet(ebdata, ecdata);
            log("マージ終了");

            TermLoadFile(ebdata, ecdata);
            ExcelApp.Release();
            Utility.ReplaceFileNames(replacedir, ExcelABMergeTool.Const.MergeName, Const.ExtensionName);
            log("完了! ");
        }
예제 #2
0
        /// <summary>
        /// Excelのシートをマージする S列をR列にコピーのみ
        /// </summary>
        /// <param name="ebdata"></param>
        /// <param name="ecdata"></param>
        static void MergeSheet(ExcelData ebdata, ExcelData ecdata)
        {
            const int sheetid = 1; // 固定で1のはず

            ebdata.SetWorkSheet(sheetid);
            ecdata.SetWorkSheet(sheetid);
            BCSheetMerge(ebdata.worksheet, ecdata.worksheet);
        }
예제 #3
0
        /// <summary>
        /// Excelデータ作成
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        static ExcelData CreateExcel(string fileName)
        {
            ExcelData ed = new ExcelData();

            log("'" + fileName + "'を作成します。");
            ed.filename = fileName;
            ed.workbook = ExcelApp.GetInstance().sWorkBook.Add();
//            ed.workbook.SaveAs(fileName); // 後でセーブ
//            ed.workbook.Worksheets.Add(Type.Missing);
            ed.sheets = ed.workbook.Sheets;
//            ed.worksheet = ed.sheets[1];
            ed.saveflag = true;
            return(ed);
        }
예제 #4
0
        /// ===============================================
        /// static
        /// ===============================================

        /// <summary>
        /// ロード
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static ExcelData LoadExcel(string filename)
        {
            ExcelData edata = new ExcelData();

            try
            {
                edata.init(filename);
            }
            catch (System.IO.FileNotFoundException)
            {
                TermExcel(edata);
            }
            return(edata);
        }
예제 #5
0
        /// <summary>
        /// Excelデータ読み込み
        /// </summary>
        /// <param name="pathExcelA"></param>
        /// <param name="pathExcelB"></param>
        /// <param name="ebdata"></param>
        /// <param name="ecdata"></param>
        static void LoadFile(string pathExcelA, string pathExcelB, ref ExcelData ebdata, ref ExcelData ecdata)
        {
            ebdata = new ExcelData();
            ecdata = new ExcelData();
            try
            {
                string localSrcDir   = Utility.GetDirectoryPath(pathExcelA);
                string localDestDir  = Utility.GetDirectoryPath(pathExcelB);
                string localMergeDir = localSrcDir + Const.MergeFolderName;
                replacedir = localMergeDir;                                                                                                                              // 保存
                string filename       = Utility.GetFileNameFromPath(pathExcelA);
                string outputfilename = Utility.GetFileNameFromPathWithoutExt(pathExcelA) + ExcelABMergeTool.Const.MergeName + Utility.GetFileNameExtension(pathExcelA); //.xlsx";
                Utility.CreateDirectory(localMergeDir);
                Utility.CreateDirectory(localSrcDir);
                Utility.CreateDirectory(localDestDir);
                {
                    log("入力ファイル:" + pathExcelA);
                    ExcelData eadata = new ExcelData();
                    string    file   = localSrcDir + filename;
                    eadata = (!Utility.CheckExistFile(file)) ? CreateExcel(file) : LoadExcel(file);
                    Utility.DeleteFile(localMergeDir + outputfilename);
                    // aを別ファイルに保存する。
                    eadata.workbook.SaveCopyAs(localMergeDir + outputfilename);
                    log("入力ファイルをコピー => " + outputfilename);
                    TermExcel(eadata); // eaは閉じる
                    log("入力ファイルは閉じる");
                }

                {
                    log("出力ファイル:" + pathExcelB);
                    string file = localDestDir + filename;
                    ebdata = (!Utility.CheckExistFile(file)) ? CreateExcel(file) : LoadExcel(file);
                    // eb開いたまま
                }

                {
                    string file = localMergeDir + outputfilename;
                    log("mergeファイルを開く:" + outputfilename);
                    ecdata          = (!Utility.CheckExistFile(file)) ? CreateExcel(file) : LoadExcel(file);
                    ecdata.saveflag = true;
                }
            }
            finally
            {
            }
        }
예제 #6
0
 /// <summary>
 /// Excelデータまとめて終了
 /// </summary>
 /// <param name="ebdata"></param>
 /// <param name="ecdata"></param>
 static void TermLoadFile(ExcelData ebdata, ExcelData ecdata)
 {
     TermExcel(ebdata);
     TermExcel(ecdata);
 }
예제 #7
0
 /// <summary>
 /// 終了
 /// </summary>
 /// <param name="edata"></param>
 static void TermExcel(ExcelData edata)
 {
     ExcelData.TermExcel(edata);
 }
예제 #8
0
 /// <summary>
 /// ロード
 /// </summary>
 /// <param name="filename"></param>
 /// <returns></returns>
 static ExcelData LoadExcel(string filename)
 {
     return(ExcelData.LoadExcel(filename));
 }
예제 #9
0
 /// <summary>
 /// 終了
 /// </summary>
 /// <param name="edata"></param>
 public static void TermExcel(ExcelData edata)
 {
     edata.term();
     GC.Collect();
 }