EXCEL中的VBA代码,帮忙转换成C#,谢谢!
各位老师好,请教如下:Sub test()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:="123"
Next ws
End Sub
以上是EXCEL中的VBA代码,如何转换成C#,恳请各位老师帮忙解决下,谢谢! 麻烦各位老师,帮忙下,谢谢!
本帖最后由 jackz007 于 2022-11-12 14:11 编辑
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;
namespace UnprotectExcelApp1
{
class Program
{
static void Main(string[] args)
{
string myPath = "Book1.xls" ;
Workbook workbook = new Workbook(myPath) ;
foreach (Worksheet sheet in workbook . Sheets)
{
sheet.Unprotect("123") ;
}
workbook.Save("MyBook1.xls") ;
}
}
}
C# 操作 Excel 需要引用 "Microsoft.Office.Interop.Excel.dll" 比较麻烦,代码只是供你参考,后面的事情你自己搞定吧。 jackz007 发表于 2022-11-12 14:01
C# 操作 Excel 需要引用 "Microsoft.Office.Interop.Excel.dll" 比较麻烦,代码只是供你参考,后 ...
非常感谢,谢谢您,老师!
页:
[1]