예제 #1
0
        private void btnOpenFileClick(object sender, EventArgs args)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Excel File(*.xlsx)|*.xlsx|Text File(*.txt)|*.txt|CSV File(*.csv)|*.csv";

            if (fileCount == 9)
            {
                drawPointX = 0; drawPointY = 0;
                MessageBox.Show("파일을 추가 할 수 없습니다. 파일 목록을 삭제 하시기 바랍니다.", "확인 바랍니다.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            excelListView excelListV = new excelListView();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                fileCount += 1;
                string s_filename = System.IO.Path.GetFileName(s_filepath);
                switch (fileCount)
                {
                case 1:
                    txb_OpenFIle1.Text = openFileDialog.FileName;
                    s_filepath         = openFileDialog.FileName;
                    break;

                case 2:
                    txb_OpenFIle2.Text = openFileDialog.FileName;
                    s_filename         = openFileDialog.FileName;
                    fileCount          = 0;
                    break;
                }

                /*
                 *
                 * s_filepath = openFileDialog.FileName;
                 * string s_filename = System.IO.Path.GetFileName(s_filepath);
                 *
                 * excelFileBindings(s_filename, s_filepath, fileCount, excelListV);
                 *
                 * if (!clbAddFileList.Items.Contains(s_filename))
                 * {
                 *  clbAddFileList.Items.Add(s_filename);
                 *  dicfullpath.Add(s_filename, s_filepath);
                 *
                 *  if ((drawPointX % 1400) == 0 && (drawPointX != 0))
                 *  { drawPointX = 0; drawPointY += 350; }
                 *  else if ((drawPointY % 700) == 0 && (drawPointY != 0))
                 *      drawPointY = 0;
                 *  excelListV.Location = new Point(drawPointX, drawPointY);
                 *  pnlMain.Controls.Add(excelListV);
                 *  excelListV.Show();
                 *  drawPointX += 350;
                 * }
                 * else
                 *  MessageBox.Show("같은 이름에 파일명이 존재합니다.", "확인 바랍니다.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 */
            }

            /*
             * object missing = System.Reflection.Missing.Value;
             * excelApp.Visible = false;
             *
             * exlWbMerge1 = (Excel.Workbook)(excelApp.Workbooks.Open(txb_OpenFIle1.Text, 0, false, 5, missing, missing, true, Excel.XlPlatform.xlWindows, "\t", true, false, 0, missing, missing, missing));
             *
             * exlSheet = (Excel.Worksheet)exlWbMerge1.ActiveSheet;
             *
             * if (fileCount == 1)
             * {
             *  Object refmissing = System.Reflection.Missing.Value;
             *  oDocument = null;
             *  webFile1.Navigate(exlWbMerge1.FullName, null, null, null);
             * }
             * else
             * {
             *
             * }
             */
        }
예제 #2
0
        private void excelFileBindings(string filename, string filepath, int fileCount, excelListView excelListV)
        {
            DataSet dataSetExcel = null;

            excelApp = new Excel.Application();

            using (var stream = File.Open(filepath, FileMode.Open, FileAccess.Read))
            {
                using (var excelreader = ExcelReaderFactory.CreateReader(stream))
                {
                    dataSetExcel = excelreader.AsDataSet(new ExcelDataSetConfiguration()
                    {
                        ConfigureDataTable = (_) => new ExcelDataTableConfiguration()
                        {
                            UseHeaderRow = true
                        }
                    });

                    dataSetExcel.Tables[0].TableName = string.Format("ExFiles_{0}", fileCount.ToString().PadLeft(2, '0'));
                    excelFilesDataSet.Tables.Add(dataSetExcel.Tables[0].Copy());

                    DataTable temp50RowDT = dataSetExcel.Tables[0].Clone();
                    temp50RowDT.TableName = string.Format("dgvE_{0}", fileCount.ToString().PadLeft(2, '0'));
                    dataGridViewsDataSet.Tables.Add(temp50RowDT);

                    //Common common = new Common();
                    //common.dataSetExcelFiles = new DataSet();
                    //common.dataSetExcelFiles.Tables.Add(temp50RowDT.Clone());

                    int limitCount = 0;

                    object[] rowArray = new object[13];
                    foreach (DataRow dataRow in dataSetExcel.Tables[0].Rows)
                    {
                        limitCount += 1;
                        temp50RowDT.ImportRow(dataRow);

                        if (limitCount >= 50)
                        {
                            break;
                        }
                    }

                    excelListV.ExcelListDT   = dataGridViewsDataSet.Tables[fileCount - 1];
                    excelListV.excelFileName = filename;
                }
            }
        }