以编程方式将 XLS 转换为 XLSB? [英] Convert XLS to XLSB Programmatically?

查看:45
本文介绍了以编程方式将 XLS 转换为 XLSB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户需要将 XLS 文件转换为 XLSB.有没有人以编程方式完成此操作(有或没有附加组件 --- 无关紧要 --- 只需要能够使其自动化)?我正在寻找一种方法来自动执行此操作.

I have a customer that needs to convert XLS files to XLSB. Has anyone done this programmatically, (with or without an add-on --- doesn't matter --- just need to be able to automate it)? I'm looking for a way to automate this.

顺便说一句,客户之所以问这个是因为他们使用 Sharepoint,而且似乎有一种方法可以比 XLS 更快更容易地分析 XLSB 文件?我正在努力提高我的 Sharepoint 知识,但与此同时,我正在尝试找到这个 XLSB 问题的答案.

As a side note, the customer is asking about this because they use Sharepoint, and it seems it has a way to analyze XLSB files quicker and easier than XLS? I'm working to improve my Sharepoint knowledge, but in the meantime, I'm trying to find an answer to this XLSB issue.

推荐答案

好吧,那么有一个短格式版本:

Well, then there is a short format verison:

using Microsoft.Office.Interop.Excel;

// init excel
Application excelApplication = new Application();

// ...

// open book in any format
Workbook workbook = excelApplication.Workbooks.Open("1.xls", XlUpdateLinks.xlUpdateLinksNever, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

// save in XlFileFormat.xlExcel12 format which is XLSB
workbook.SaveAs("1.xlsb", XlFileFormat.xlExcel12, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

// close workbook
workbook.Close(false, Type.Missing, Type.Missing);

// ...

// shutdown excel
excelApplication.Quit();

您将需要具有 .NET 编程支持的 Excel 安装(在安装程序中默认禁用!)并从您的项目中引用 Excel 的 MS Office PIA 程序集:

You will need a Excel installation with .NET programming support (disabled by default in installer!) and reference MS Office PIA assembly for Excel from your project:

参考资料:工作簿.打开workbook.SaveAs, XlFileFormat.xlExcel12

这篇关于以编程方式将 XLS 转换为 XLSB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆