Example #1
0
        private void openExcel_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter          = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx|所有文件|*.*";
            ofd.ValidateNames   = true;
            ofd.CheckPathExists = true;
            ofd.CheckFileExists = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string strFileName = ofd.FileName;
                try
                {
                    excelDt = NPOIExcel.readExcel(strFileName, true);
                    if (excelDt != null && excelDt.Rows.Count > 0)
                    {
                        LogRichTextBox.logMesg("文件『" + strFileName + "』读取成功!共读取【" + excelDt.Rows.Count.ToString() + "】条记录。");
                    }
                    else
                    {
                        LogRichTextBox.logMesg("文件『" + strFileName + "』读取失败!请检查EXCEL文件是否有数据。", 2);
                    }
                }
                catch (Exception ex)
                {
                    LogRichTextBox.logMesg("文件『" + strFileName + "』读取失败!失败原因为:" + ex.ToString(), 2);
                    return;
                }
            }
        }
Example #2
0
        private void openExcel_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter          = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx|所有文件|*.*";
            ofd.ValidateNames   = true;
            ofd.CheckPathExists = true;
            ofd.CheckFileExists = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string strFileName = ofd.FileName;
                try
                {
                    excelDt = NPOIExcel.readExcel(strFileName, true);
                    int    index = excelDt.Rows.Count - 1;
                    string heji  = excelDt.Rows[index]["单据日期"].ToString();
                    if (heji.Equals("合计"))
                    {
                        excelDt.Rows.RemoveAt(index);
                    }
                    LogRichTextBox.logMesg("文件『" + strFileName + "』读取成功!共读取【" + excelDt.Rows.Count.ToString() + "】条记录。");
                }
                catch (Exception ex)
                {
                    LogRichTextBox.logMesg("文件『" + strFileName + "』读取失败!失败原因为:" + ex.ToString(), 2);
                    return;
                }
                impU8.Enabled = checkData();
            }
        }