c++/vb6/.net如何开发一个脱端的excel读取工具?

发布网友 发布时间:2022-04-22 08:09

我来回答

3个回答

热心网友 时间:2022-06-18 08:45

.net平台下有 Spire.XLS for .NET,这个就是不依赖本机安装Excel就可以操作excel的工具,常用的数据读取、导入/导出也都可以,下面是读取加密的excel demo示例,你参考看看,使用语言C#和VB.NET:

读取加密的workbook,然后解除密码保护

【C#】

using Spire.Xls;

namespace UnProtestedWordbook_XLS

{

class Program

{

static void Main(string[] args)

{

//初始化一个Workbook实例

Workbook workbook = new Workbook();

//输入密码并加载文档

workbook.OpenPassword = ("123");

workbook.LoadFromFile("test.xlsx", ExcelVersion.Version2013);

//取消保护

workbook.UnProtect();

//保存并打开文档

workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2013);

System.Diagnostics.Process.Start("Output.xlsx");

}

}

}

【VB.NET】

Imports Spire.Xls

Namespace UnProtestedWordbook_XLS

Class Program

Private Shared Sub Main(args As String())

'初始化一个Workbook实例

Dim workbook As New Workbook()

'输入密码并加载文档

workbook.OpenPassword = ("123")

workbook.LoadFromFile("test.xlsx", ExcelVersion.Version2013)

'取消保护

workbook.UnProtect()

'保存并打开文档

workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2013)

System.Diagnostics.Process.Start("Output.xlsx")

End Sub

End Class

End Namespace


2. 读取加密的worksheet, 然后解除密码保护

【C#】

using Spire.Xls;

namespace UnProtectWorksheet_XLS

{

class Program

{

static void Main(string[] args)

{

//初始化一个工作簿并加载一个工作簿实例

Workbook book = new Workbook();

book.LoadFromFile("ProtectedWorksheet.xlsx");

//获取工作簿中第一个工作表

Worksheet sheet = book.Worksheets[0];

//设置撤销保护的密码

sheet.Unprotect("myworksheet");

//保存并打开文件

book.SaveToFile("UnProtectedWorksheet.xlsx", ExcelVersion.Version2010);

System.Diagnostics.Process.Start("UnProtectedWorksheet.xlsx");

}

}

}

【VB.NET】

Imports Spire.Xls

Namespace UnProtectWorksheet_XLS

Class Program

Private Shared Sub Main(args As String())

'初始化一个工作簿并加载一个工作簿实例

Dim book As New Workbook()

book.LoadFromFile("ProtectedWorksheet.xlsx")

'获取工作簿中第一个工作表

Dim sheet As Worksheet = book.Worksheets(0)

'设置撤销保护的密码 

sheet.Unprotect("myworksheet")

'保存并打开文件

book.SaveToFile("UnProtectedWorksheet.xlsx", ExcelVersion.Version2010)

System.Diagnostics.Process.Start("UnProtectedWorksheet.xlsx")

End Sub

End Class

End Namespace

热心网友 时间:2022-06-18 08:46

搜了下,有python工具支持解密
pip install msoffcrypto-tool

命令行:msoffcrypto-tool Myfile.xlsx Myfile-decrypted.xlsx -p "密码"

import msoffcryptoimport openpyxl

decrypted_workbook = io.BytesIO()with open('Myfile.xlsx', 'rb') as file:
office_file = msoffcrypto.OfficeFile(file)
office_file.load_key(password='密码')
office_file.decrypt(decrypted_workbook)

热心网友 时间:2022-06-18 08:46

net有大把的,VB6就比较少

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com