コード例 #1
0
        private string GetUpdateValues()
        {
            string sColumnHeader = "ERROR";
            string sFilePath = OpenExcelWorkbook();

            if (sFilePath == "ERROR")
                MessageBox.Show("Could not open file.  Please select a different file", "File Open Error", MessageBoxButtons.OK);
            else
            {
                if (wb != null)
                {
                    frmSelectSheet frmSheetSelect = new frmSelectSheet();
                    frmSheetSelect.wb = wb;
                    frmCursor = System.Windows.Forms.Cursors.Default;
                    frmSheetSelect.ShowDialog();
                    frmCursor = System.Windows.Forms.Cursors.WaitCursor;

                    if (!String.IsNullOrEmpty(sSelectedSheet) && sSelectedSheet != "" && sSelectedSheet.Length > 0)
                    {
                        bool bFoundSheet = false;

                        for (int i = 1; i <= wb.Worksheets.Count; i++)
                        {
                            if (((Worksheet)wb.Worksheets[i]).Name == sSelectedSheet)
                            {
                                ws = (Worksheet)wb.Worksheets[i];
                                bFoundSheet = true;
                                break;
                            }
                        }

                        if (bFoundSheet)
                        {
                            Range rng = (Range)ws.Cells[1, 1];
                            sColumnHeader = rng.Text.ToString();
                        }
                    }
                }
                else
                    MessageBox.Show("Could not open file.  Please select a different file", "File Open Error", MessageBoxButtons.OK);

            }

            return sColumnHeader;
        }
コード例 #2
0
 private void GetSheet()
 {
     frmSelectSheet formSelectSheet = new frmSelectSheet();
     //formSelectSheet.sFilePath = txtFile.Text;
     formSelectSheet.ShowDialog();
 }