Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.Filter = "*.xl*|*.*";
            openFileDialog1.ShowDialog();
            fileName= openFileDialog1.FileName;
            if (biliDanmu != null&&fileName!="" )
            {
                biliDanmu.AddDMText("文件", fileName,"g");
            }
            if(fileName.EndsWith("xls")||fileName.EndsWith("xlsx") || fileName.EndsWith("xlsm"))
            {
                //创建
                Excel.Application xlApp = new Excel.Application();
                xlApp.DisplayAlerts = false;
                xlApp.Visible = false;
                xlApp.ScreenUpdating = false;
                //打开Excel
                Excel.Workbook xlsWorkBook = xlApp.Workbooks.Open(fileName, System.Type.Missing, System.Type.Missing, System.Type.Missing,
                System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing,
                System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);

                //处理数据过程,更多操作方法自行百度
                Excel.Worksheet sheet = xlsWorkBook.Worksheets[1];//工作薄从1开始,不是0
                MessageBox.Show(sheet.Cells[1, 1].FormulaR1C1Local) ;

                //另存
                //xlsWorkBook.SaveAs(exportExcelPath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange,
                //    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                //关闭Excel进程
                ClosePro(xlApp, xlsWorkBook);
            }

        }
Пример #2
0
 private void btnTest_Click(object sender, RoutedEventArgs e)
 {
     if (biliDanmu != null)
     {
         biliDanmu.AddDMText("文件", "hello", "g");
     }
 }