Tag: 处理

使用xlrd跟踪错误的文件名

我正在使用xlrd打开一个“.xlsx”文件,并从中读取数据进行修改。 如果文件名存在,一切正常。 但如果文件不存在,我会得到一个回溯。 我正在使用的代码是(只是相关的部分): from xlrd import open_workbook, XLRDError from xlwt import * filename = "./resources/tags_meters.xlsx" bad_filename = "./resources/meters.txt" # Use this to test bad filenames filename = bad_filename 还有我使用函数来检查文件是否可以打开: def test_book(filename): try: open_workbook(filename) except XLRDError as e: print "error is" + e.message return False else: return True if test_book(filename): print "Book Ok … Opening […]

searchExcel事件之前打开或其他解决scheme

我正在开发一个Excel COM-Addin,它将打开预定义的Excel模板/文件。 为了确保excel模板只能与插件结合使用,我想对某些文件进行密码保护。 棘手的部分是find或定义一个开放的工作簿 – 事件。 目标是交出密码,并打开文件,而不会得到一个提示窗口。 我已经尝试过,并且发生了以下事件: 1。 EventDel_BookOpen = New Excel.AppEvents_WorkbookOpenEventHandler(AddressOf OpenWorkbook) AddHandler xlApp.WorkbookOpen, EventDel_BookOpen Private Sub OpenWorkbook(ByVal wb As Excel.Workbook) If wb.HasPassword Then wb.Password = "test" End If End Sub popup提示窗口后触发事件。 2。 EventDel_WBookOpen = New Excel.WorkbookEvents_OpenEventHandler(AddressOf WBOpenWorkbook) AddHandler xlBook.Open, EventDel_WBookOpen Private Sub WBOpenWorkbook() If xlBook.HasPassword Then wb.Password = "test" End If End […]

为什么我的Excel办公室对象留下了EXCEL.exe进程?

可能重复: 如何正确清理C#中的Excel互操作对象 我有一个应用程序使用Office Interop库C#。 这个库是从IIS7托pipe的ASP.NET应用程序调用的。 相关的代码位是: /// <summary> /// Provides excel functions. /// </summary> public class ExcelStuff : IDisposable { #region Excel Components // The following are pre-allocated Excel objects that must be explicitly disposed of. private Excel.Application xApp; private Excel.Workbooks xWorkbooks; private Excel.Workbook xWorkbook; private Excel.Sheets xWorksheets; private Excel.Worksheet xWorksheet; private Excel.ChartObjects xCharts; private […]

在C#中安全地configurationExcel互操作对象?

我正在一个winforms c#visual studio 2008应用程序。 该应用程序会谈excel文件,我正在使用Microsoft.Office.Interop.Excel; 去做这个。 我想知道如何确保即使有错误,对象也被释放? 这是我的代码: private void button1_Click(object sender, EventArgs e) { string myBigFile=""; OpenFileDialog openFileDialog1 = new OpenFileDialog(); DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result. myBigFile=openFileDialog1.FileName; Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; string str; int rCnt = 0; int cCnt = […]