Пример #1
0
        private void Import()
        {
            try
            {
                m_dgv_ItemDetail.Rows.Clear();
                m_dgv_ItemDetail.Columns.Clear();

                ExcelFile ef = ExcelFile.Load(this.m_TaskCsvName);

                DataGridView dgv = new DataGridView();
                DataGridViewConverter.ExportToDataGridView(ef.Worksheets.ActiveWorksheet, dgv, new ExportToDataGridViewOptions()
                {
                    ColumnHeaders = true
                });

                //PrintColumnText(new PB.Task());

                for (int row_index = 0; row_index < dgv.Rows.Count - 1; ++row_index) //Default datagridview has 1 record
                {
                    int new_index = this.m_dgv_ItemDetail.Rows.Add();
                    for (int column_index = 0; column_index < dgv.Rows[row_index].Cells.Count; ++column_index)
                    {
                        this.m_dgv_ItemDetail.Rows[new_index].Cells[column_index].Value = dgv.Rows[row_index].Cells[column_index].Value;
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("文件导入失败:" + ex.Message, "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            }
        }
Пример #2
0
        private void fillDataGrid()
        {
            var workbook = ExcelFile.Load((String)Directory.GetCurrentDirectory().ToString() + "\\PowerSpreadSheet\\PowerPrice.xlsx");

            DataGridViewConverter.ExportToDataGridView(workbook.Worksheets.ActiveWorksheet, this.dataGridView1, new ExportToDataGridViewOptions()
            {
                ColumnHeaders = true
            });
        }
Пример #3
0
        private void Upload_quote_btn_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog();

            openFileDialog.Filter      = "XLS files (*.xls, *.xlt)|*.xls;*.xlt|XLSX files (*.xlsx, *.xlsm, *.xltx, *.xltm)|*.xlsx;*.xlsm;*.xltx;*.xltm|ODS files (*.ods, *.ots)|*.ods;*.ots|CSV files (*.csv, *.tsv)|*.csv;*.tsv|HTML files (*.html, *.htm)|*.html;*.htm";
            openFileDialog.FilterIndex = 2;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                var workbook = ExcelFile.Load(openFileDialog.FileName);

                // From ExcelFile to DataGridView.
                DataGridViewConverter.ExportToDataGridView(workbook.Worksheets.ActiveWorksheet, this.dataGridView1, new ExportToDataGridViewOptions()
                {
                    ColumnHeaders = true
                });
            }

            /*
             * for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
             * {
             *
             *
             *  Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value);
             *  Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value);
             *  Convert.ToDecimal(dataGridView1.Rows[i].Cells[5].Value);
             *  Convert.ToDecimal(dataGridView1.Rows[i].Cells[6].Value);
             * }
             */
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                //multiply qty  by cog and add the result to cogItem
                cogItem += Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value) * Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value);
                total_sale_label.Text = "Total CoG: $" + cogItem.ToString();

                //adds the row total to sumprofit
                sumProfit       += Convert.ToDouble(dataGridView1.Rows[i].Cells[7].Value);
                total_label.Text = "Total: $" + sumProfit.ToString();

                //subtract to obtain the total earnings
                totalProf = sumProfit - cogItem;
                total_profit_label.Text = "Total Profit: $" + totalProf.ToString();

                //calculate average markup for quote
                percentAve         = ((totalProf / cogItem) * 100);
                percent_label.Text = "MarkUp Average: " + Math.Round(percentAve, 2).ToString() + "%";



                i++;
            }
        }
Пример #4
0
        private void LoadExcelToDataGridView(string excelFile)
        {
            ExcelFile      ef = ExcelFile.Load(excelFile);
            ExcelWorksheet ws = ef.Worksheets[0];

            // From ExcelFile to DataGridView.
            DataGridViewConverter.ExportToDataGridView(
                ws,
                this.dataGridView1,
                new ExportToDataGridViewOptions()
            {
                ColumnHeaders = true
            });
        }
Пример #5
0
        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "XLS files(*.xls)|*.xls";
            ofd.FilterIndex = 3;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                dataGridView1.Columns.Clear();
                ExcelFile ef = ExcelFile.Load(ofd.FileName);
                DataGridViewConverter.ExportToDataGridView(ef.Worksheets.ActiveWorksheet, this.dataGridView1, new ExportToDataGridViewOptions()
                {
                    ColumnHeaders = true
                });
            }
        }
Пример #6
0
        private void btn_agregarArchivo_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "XLS files (*.xls, *.xlt)|*.xls;*.xlt|XLSX files (*.xlsx, *.xlsm, *.xltx, *.xltm)|*.xlsx;*.xlsm;*.xltx;*.xltm|ODS files (*.ods, *.ots)|*.ods;*.ots|CSV files (*.csv, *.tsv)|*.csv;*.tsv|HTML files (*.html, *.htm)|*.html;*.htm";
            //openFileDialog.FilterIndex = 2;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                ExcelFile ef = ExcelFile.Load(openFileDialog.FileName);

                // Export Excel worksheet to DataGridView control.
                DataGridViewConverter.ExportToDataGridView(ef.Worksheets.ActiveWorksheet, this.dataGridView1, new ExportToDataGridViewOptions()
                {
                    ColumnHeaders = true
                });
            }
        }
Пример #7
0
    private void btnLoadFile_Click(object sender, EventArgs e)
    {
        var openFileDialog = new OpenFileDialog();

        openFileDialog.Filter      = "XLS files (*.xls, *.xlt)|*.xls;*.xlt|XLSX files (*.xlsx, *.xlsm, *.xltx, *.xltm)|*.xlsx;*.xlsm;*.xltx;*.xltm|ODS files (*.ods, *.ots)|*.ods;*.ots|CSV files (*.csv, *.tsv)|*.csv;*.tsv|HTML files (*.html, *.htm)|*.html;*.htm";
        openFileDialog.FilterIndex = 2;

        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
            var workbook = ExcelFile.Load(openFileDialog.FileName);

            // From ExcelFile to DataGridView.
            DataGridViewConverter.ExportToDataGridView(workbook.Worksheets.ActiveWorksheet, this.dataGridView1, new ExportToDataGridViewOptions()
            {
                ColumnHeaders = true
            });
        }
    }
Пример #8
0
        private void btnExaminar_Click(object sender, EventArgs e)
        {
            OpenFileDialog OpenFlDialog = new OpenFileDialog();

            OpenFlDialog.Filter      = "XLS files (*.xls, *.xlt)|*.xls;*.xlt|XLSX files (*.xlsx, *.xlsm, *.xltx, *.xltm)|*.xlsx;*.xlsm;*.xltx;*.xltm|ODS files (*.ods, *.ots)|*.ods;*.ots|CSV files (*.csv, *.tsv)|*.csv;*.tsv|HTML files (*.html, *.htm)|*.html;*.htm";
            OpenFlDialog.FilterIndex = 2;

            if (OpenFlDialog.ShowDialog() == DialogResult.OK)
            {
                StartLoading();
                txtRutaArchivo.Text = OpenFlDialog.FileName.Trim();
                var workBook = ExcelFile.Load(OpenFlDialog.FileName);
                DataGridViewConverter.ExportToDataGridView(workBook.Worksheets.ActiveWorksheet, listCotizaciones, new ExportToDataGridViewOptions()
                {
                    ColumnHeaders = true
                });
                btnGuardar.Enabled = true;
                CloseLoading();
            }
        }
Пример #9
0
 private void tabControl1_Selected(object sender, TabControlEventArgs e)
 {
     if (tabControl1.SelectedIndex != -1)
     {
         DataGridViewConverter.ExportToDataGridView(
             File.Tables.Worksheets[tabControl1.SelectedIndex],
             this.tableGridView1,
             new ExportToDataGridViewOptions()
         {
             ColumnHeaders = true
         });
         SelectColumComboBox.Items.Clear();
         for (int i = 0; i < tableGridView1.Columns.Count; i++)
         {
             SelectColumComboBox.Items.Add(tableGridView1.Columns[i].HeaderText);
         }
         tabControl1.SelectedTab.Controls.Add(tableGridView1);
         tableGridView1.Location = new Point(0, 0);
         tableGridView1.Size     = PreferredSize;
         tableGridView1.AutoResizeColumns();
         tableGridView1.AutoResizeRows();
     }
 }