惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LINUX DO - 最新话题
Recorded Future
Recorded Future
月光博客
月光博客
博客园 - 【当耐特】
博客园 - 叶小钗
宝玉的分享
宝玉的分享
量子位
雷峰网
雷峰网
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Vercel News
Vercel News
L
LangChain Blog
B
Blog
Y
Y Combinator Blog
爱范儿
爱范儿
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
博客园 - Franky
P
Palo Alto Networks Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
Scott Helme
Scott Helme
I
Intezer
T
The Exploit Database - CXSecurity.com
MyScale Blog
MyScale Blog
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Troy Hunt's Blog
N
News and Events Feed by Topic
大猫的无限游戏
大猫的无限游戏
F
Fortinet All Blogs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Security Affairs
Cyberwarzone
Cyberwarzone
PCI Perspectives
PCI Perspectives
小众软件
小众软件
D
DataBreaches.Net
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Know Your Adversary
Know Your Adversary
Forbes - Security
Forbes - Security
S
Securelist
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
The Last Watchdog
The Last Watchdog

博客园 - 愚公

Bridges 虚拟化浪潮 MAGEUI的Hash问题 Lingoes的划词翻译功能极有可能泄露隐私 Vista Folders Always Shown In Details View - 让Vista文件夹总是使用详细资料视图 用7zip制作自动解压安装程序 安装新的Oracle Instant Client后重新配置PL/SQL Developer和环境: Certificates registry key name to MMC friendly name mapping A review of the CVS SCC PLUGIN IE8.0 TAB行为悄然改善: WSS 3.0 List WebService使用点滴 Set a password textbox for Visual Studio .NET setup project 在WinForm中控制GIF动画的启停的一种方法 foobar2000绿色版在vista下的Unhandled exception: Bad allocation Virtual Server启动时自动启动每个虚机 NTFS文件及目录日期值行为 installState is missing ! .Net Framework 2.0配置工具Stopped Working VISTA BITS POLICY DESCRIPTION'S MISTAKE
VSTO SaveCopyAs方法在Excel 2007下必须注意的一个问题
愚公 · 2008-10-22 · via 博客园 - 愚公

SaveCopyAs是与Excel当前的默认保存设置格式相关的,它不会根据文件名后缀来自动调整保存的格式,也就是说,如果你设置默认存储格式为Excel 97-2003 Workbook(.xls)格式,而SaveCopyAs参数里的文件名是.xlsx的话,其实真正的格式仍然是.xls的,在这种情况下,你用Excel 2007去打开这个.xlsx文件,Excel程序就无法识别文件,从而弹出这样的警告:

Excel 无法打开文件“xxxxx.xlsx”,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配。
Excel cannot open the file 'xxxxx.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.

因此,我们在调用SaveCopyAs之前最好探测一下当前的默认保存格式设置,本设置在如下注册表项中:

HKCU:Software\Microsoft\Office\12.0\Excel\Options\DefaultFormat(DWord)

若不存在本注册项,说明默认为OpenXML格式.xlsx,若存在,则0x38(56)是97-2003工作簿.xls格式,0x33(51)为.xlsx。

另外,用VSTO生成文档后,一般建议将其中的Customization关联代码去掉,否则外部用户打开文档时会出现令人讨厌的对话框。

defaultExtension = ".xlsx";
excel2007Options 
= Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office\\12.0\\Excel\\Options");
if (excel2007Options != null)
{
   
int s = (int)excel2007Options.GetValue("DefaultFormat");
   
if (s == 56) defaultExtension = ".xls";
}
string filename = "workbookName" + defaultExtension;
if (System.IO.File.Exists(filename)) System.IO.File.Delete(filename);
this.SaveCopyAs(filename);
if (ServerDocument.GetCustomizationVersion(filename) == 3) ServerDocument.RemoveCustomization(filename);