Exemple #1
0
        private void btnLoadExcel_Click(object sender, System.EventArgs e)
        {
            frmMain.labStatus.Text = "";
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (lstExcel.Tag != null && File.Exists(lstExcel.Tag.ToString()))
            {
                openFileDialog1.InitialDirectory = Path.GetFullPath(lstExcel.Tag.ToString());
            }
            else
            {
                openFileDialog1.InitialDirectory = Path.GetFullPath(Application.ExecutablePath);
            }
            openFileDialog1.Filter      = "テーブルレイアウトファイル(*.xls)|*.xls";
            openFileDialog1.Title       = "テーブルレイアウトファイルを選択してください。";
            openFileDialog1.Multiselect = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string[] sExcelName = openFileDialog1.FileNames;
                lstExcel.Tag = sExcelName[0];
                for (int i = 0; i < sExcelName.Length; i++)
                {
                    if (lstExcel.FindString(sExcelName[i]) >= 0)
                    {
                        continue;
                    }
                    lstExcel.Items.Add(sExcelName[i]);
                    frmMain.labStatus.Text = "Now is getting excle file information...";
                    Application.DoEvents();

                    string   sConnExcel = cc.OleDB.ConnStringExcel(sExcelName[i], false);
                    cc.OleDB dbExcel    = new cc.OleDB(sConnExcel);
                    if (dbExcel.Error())
                    {
                        frmMain.msg.println("Open Excel File Error:");
                        frmMain.msg.println("File:" + sExcelName[i]);
                        frmMain.msg.println(dbExcel.Exception.Message, Color.Red);
                        return;
                    }
                    string[] sSheetsName = dbExcel.GetExcelSheetsName();
                    if (sSheetsName != null)
                    {
                        foreach (string s in sSheetsName)
                        {
                            lstExcel.Items.Add("  " + s);
                        }
                    }
                    frmMain.labStatus.Text = "Now is getting excle file information...OK";
                    dbExcel.Dispose();
                }
            }
        }
Exemple #2
0
        private void btnExcelTemp_Click(object sender, System.EventArgs e)
        {
            frmMain.labStatus.Text = "";
            string initpath  = Path.GetDirectoryName(Application.ExecutablePath);
            string sfilename = txtExcelTemp.Text.Trim();

            if (sfilename.StartsWith(".\\"))
            {
                sfilename = initpath + sfilename.Substring(1);
            }
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            if (File.Exists(sfilename))
            {
                openFileDialog1.InitialDirectory = Path.GetFullPath(sfilename);
            }
            else
            {
                openFileDialog1.InitialDirectory = Path.GetFullPath(Application.ExecutablePath);
            }
            openFileDialog1.Filter = "テーブルレイアウトTemplateファイル(*.xls)|*.xls";
            openFileDialog1.Title  = "テーブルレイアウトTemplateファイルを選択してください。";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                lstExcelTemp.Items.Clear();

                string sExcelName = openFileDialog1.FileName;
                if (Path.GetDirectoryName(sExcelName).StartsWith(initpath))
                {
                    txtExcelTemp.Text = sExcelName.Substring(initpath.Length);
                    if (txtExcelTemp.Text.StartsWith("\\"))
                    {
                        txtExcelTemp.Text = "." + txtExcelTemp.Text;
                    }
                }
                else
                {
                    txtExcelTemp.Text = sExcelName;
                }

                frmMain.labStatus.Text = "Now is getting excle file information...";
                Application.DoEvents();

                string   sConnExcel = cc.OleDB.ConnStringExcel(sExcelName, false);
                cc.OleDB dbExcel    = new cc.OleDB(sConnExcel);
                if (dbExcel.Error())
                {
                    frmMain.msg.println("Open Excel File Error:");
                    frmMain.msg.println("File:" + sExcelName);
                    frmMain.msg.println(dbExcel.Exception.Message, Color.Red);
                    return;
                }
                string[] sSheetsName = dbExcel.GetExcelSheetsName();
                if (sSheetsName != null)
                {
                    foreach (string s in sSheetsName)
                    {
                        lstExcelTemp.Items.Add(s);
                    }
                }
                dbExcel.Dispose();
                if (lstExcelTemp.Items.Count > 0)
                {
                    lstExcelTemp.SetItemChecked(0, true);
                    frmMain.labStatus.Text = "Now is getting excle file information...OK";
                }
                else
                {
                    frmMain.msg.println("This Excel file not include Template information.", Color.Red);
                    frmMain.labStatus.Text = "Now is getting excle file information...no Template included";
                }
            }
        }