首页 新闻 会员 周边 捐助

导出Excel文件,打开后显示输入密码。求教如何解决

0
悬赏园豆:5 [已解决问题] 解决于 2013-01-07 10:50
 private void MenuItem_Click(object sender, RoutedEventArgs e)
        {

            System.Data.DataTable datatable = new System.Data.DataTable();
            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            try
            {
                //lz 路径选择

                excelApp.Visible = false;
                Workbook excelWB = excelApp.Workbooks.Add(System.Type.Missing);
                Worksheet excelWS = (Worksheet)excelWB.Worksheets[1];
                Range celulas = null;
                celulas = excelWS.get_Range("A1", System.Type.Missing);
                excelWS.Cells[1, 1] = "";
                excelWS.Cells[1, 2] = "控制柜名称";
                excelWS.Cells[1, 3] = "控制柜分类";
                excelWS.Cells[1, 4] = "时间";
                excelWS.Cells[1, 6] = "工作模式";
                excelWS.Cells[1, 8] = "报警状态";
                excelWS.Cells[1, 10] = "输入电压";
                excelWS.Cells[1, 11] = "输出电压";
                excelWS.Cells[1, 12] = "输出电流";
                excelWS.Cells[1, 13] = "一路";
                excelWS.Cells[1, 14] = "二路";

                for (int i = 0; i < dsResult.Tables[0].Rows.Count; i++)
                {
                    for (int j = 0; j < dsResult.Tables[0].Columns.Count; j++)
                    {
                        celulas.get_Offset(i + 1, j).Cells.Value2 = dsResult.Tables[0].Rows[i][j].ToString();
                    }
                }

                excelApp.ActiveWorkbook.RefreshAll();
                excelApp.Workbooks.Application.ActiveWorkbook.RefreshAll();

                SaveFileDialog a = new SaveFileDialog();
                a.Filter = "Excel 工作簿 (*.xls)|*.xls";
                a.ShowDialog();
                excelWB.SaveAs(a.FileName, XlSaveAction.xlSaveChanges, false, false, XlSaveAsAccessMode.xlNoChange);
                excelWB.Close(false, null, null);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("导出失败:" + ex.Message);

            }

            excelApp.Quit();
            System.Windows.Forms.MessageBox.Show("导出成功!");
            btnExcel.DataContext = "";
            HistoryWorkingDataGrid.DataContext = null;
        }

导出的Excel文件为什么有密码呢?

董毛毛的主页 董毛毛 | 初学一级 | 园豆:122
提问于:2013-01-07 10:25
< >
分享
最佳答案
0

SaveAs(fileNameString, Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8,
                                    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
                                    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

收获园豆:5
Launcher | 高人七级 |园豆:45050 | 2013-01-07 10:40

fileNameString这个事什么意思?

董毛毛 | 园豆:122 (初学一级) | 2013-01-07 10:43

好了。。万分感谢呀。都帮我解决俩问题了,大神威武

董毛毛 | 园豆:122 (初学一级) | 2013-01-07 10:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册