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

推荐订阅源

S
Secure Thoughts
T
The Exploit Database - CXSecurity.com
W
WeLiveSecurity
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
P
Privacy & Cybersecurity Law Blog
Help Net Security
Help Net Security
L
LINUX DO - 最新话题
H
Hacker News: Front Page
H
Heimdal Security Blog
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
Know Your Adversary
Know Your Adversary
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
Recorded Future
Recorded Future
阮一峰的网络日志
阮一峰的网络日志
T
Tor Project blog
D
DataBreaches.Net
V
Visual Studio Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
The Hacker News
The Hacker News
A
Arctic Wolf
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
P
Proofpoint News Feed
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
WordPress大学
WordPress大学
Scott Helme
Scott Helme
酷 壳 – CoolShell
酷 壳 – CoolShell
SecWiki News
SecWiki News
The Cloudflare Blog
N
News and Events Feed by Topic
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
小众软件
小众软件
博客园 - Franky
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Attack and Defense Labs
Attack and Defense Labs
T
Threat Research - Cisco Blogs

博客园 - 阿哲

SqlServer 2005 快速设置字段/表 的描述字段 string:值类型?引用类型?[转] SqlServer2005常用sql语句 SQL中FOR XML子句的各种用法 获得Windows中文件类型名称 完成类似QQ邮箱中‘HTML方式查看’功能查看Office文件 vs2008生成自定义dll,VS2008发布、生成网站时设置固定的dll文件名 开源.Net CMS系统 [转] 测试使用Windows Live Writter写Blog 试用Windows Live Mail OutlookExpress使用技巧 剩余的GMail邀请 实体类+自定义控件=? 用反射+特性列出所有的枚举变量及其描述信息,绑定到DropDownList上。 有关.NET和RS232设备通讯 .NET资源(收藏) 转:使用P/Invoke来开发用于与串行设备通讯的.NET基类(翻译) 最近有空,研究了一下.NET的通讯方面 实体和实体的集合-续2
将Visio文件装换成HTML文件(在服务器上转换,客户端无需安装visio即可查看)
阿哲 · 2009-05-22 · via 博客园 - 阿哲

需求见我的前一篇文章:类似QQ邮箱中‘HTML方式查看’功能查看Office文件

当时是直接写的一个方法,支持word、excel、ppt文件,现在写visio文件,则改成了单例模式。

废话不说,上代码: 

public class VisioApplication
{
    
private static readonly object sync = new object();
    
private static Microsoft.Office.Interop.Visio.Application vso;
    
private VisioApplication() { }public static Microsoft.Office.Interop.Visio.Application GetInstance()
    {
        
//单例模式,双重锁定
        if (vso == null)
        {
            
lock (sync)
            {
                
if (vso == null)
                {
                    vso 
= new Microsoft.Office.Interop.Visio.Application();
                    vso.Visible 
= false;//打开应用程序就隐藏
                    vso.AlertResponse = (short)1;//重要:转换时不用打开确认窗口,直接转换
                }
            }
        }
        
return vso;
    }
public static void Quit()
    {

        
if (vso != null)
        {
            vso.Quit();
        }
        GC.Collect();
    }
/// <summary>
    
/// 将Visio文档转换成HTML格式
    
/// </summary>
    
/// <param name="VisioFilePath"></param>
    public static void VisioToHtmlFile(string VisioFilePath)
    {
        Microsoft.Office.Interop.Visio.Application vso 
= GetInstance();
        Microsoft.Office.Interop.Visio.Document doc 
= null;
        Microsoft.Office.Interop.Visio.SaveAsWeb.VisSaveAsWeb saveAsWeb;
        Microsoft.Office.Interop.Visio.SaveAsWeb.VisWebPageSettings webPageSettings;
        
try
        {
            
//设置输出文件路径
            string strTarget = VisioFilePath.Substring(0, VisioFilePath.LastIndexOf(".")) + ".html";
            
//打开文档,本来想后台打开,但是无论如何都会闪一下,看大家有没有什么好的办法
            doc = vso.Documents.OpenEx(VisioFilePath,
                (
short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenRO
                
+ (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenMinimized
                
+ (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenHidden
                
+ (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenNoWorkspace);
            
//获得转换html文件用的对象
            saveAsWeb = (Microsoft.Office.Interop.Visio.SaveAsWeb.VisSaveAsWeb)vso.SaveAsWebObject;
            
//设置格式
            webPageSettings = (Microsoft.Office.Interop.Visio.SaveAsWeb.VisWebPageSettings)saveAsWeb.WebPageSettings;
            webPageSettings.TargetPath 
= strTarget;
            webPageSettings.QuietMode 
= 1;
            webPageSettings.SilentMode 
= 1;//安静模式,不然会显示转换进度窗口

            saveAsWeb.AttachToVisioDoc(doc);
//将文档添加到需要转换的列表中
            saveAsWeb.CreatePages();//开始转换
        }
        
finally
        {
            
if (doc != null)
            {
                doc.Close();
            }
        }
    }
}

本例子代码在VS2008、Office Visio 2007下测试通过,使用前需引用 相应的com组件

放在首页的原因是:希望大家帮个忙!如何让visio程序打开的时候不显示,在后台打开,我写的代码无论如何都会闪一下,谢谢!。