首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

施用OpenXml 2.0向Excel文档加入自定义Ribbon

2012-08-30 
使用OpenXml 2.0向Excel文档加入自定义RibbonRibbon.xmlImports log4netImports System.Windows.FormsImpo

使用OpenXml 2.0向Excel文档加入自定义Ribbon

Ribbon.xml

Imports log4netImports System.Windows.FormsImports System.IOImports DocumentFormat.OpenXml.PackagingImports DocumentFormat.OpenXml.Office.CustomUIModule Module1    Private MyLog As ILog = log4net.LogManager.GetLogger(GetType(Module1))    Sub Main()        Dim OFD As New OpenFileDialog        Dim TargetFile As String        Dim SourceFile As String        Dim RibbonXml As String        Dim RibbonExtend As RibbonExtensibilityPart        OFD.Multiselect = False        OFD.Title = "打开目标Excel文件"        OFD.InitialDirectory = System.Environment _            .GetFolderPath(System.Environment.SpecialFolder.Desktop)        OFD.Filter = "Excel文件|*.xlsx;*.xlsm"        OFD.ShowDialog()        TargetFile = OFD.FileName        MyLog.Info("Target File : " + TargetFile)        OFD.Title = "打开RibbonXml文件"        OFD.Filter = "Ribbon Xml文件|*.xml"        OFD.ShowDialog()        SourceFile = OFD.FileName        MyLog.Info("Source File : " + SourceFile)        RibbonXml = File.OpenText(SourceFile).ReadToEnd()        MyLog.Info("Ribbon Xml : " + RibbonXml)        Using SSD As SpreadsheetDocument = SpreadsheetDocument _                                           .Open(TargetFile, True)            RibbonExtend = SSD.GetPartsOfType(Of RibbonExtensibilityPart)() _                .FirstOrDefault()            If RibbonExtend Is Nothing Then                RibbonExtend = SSD.AddRibbonExtensibilityPart()            Else                RibbonExtend.CustomUI = New CustomUI(RibbonXml)                RibbonExtend.CustomUI.Save()            End If        End Using        Console.ReadKey()    End SubEnd Module

欢迎访问《许阳的红泥屋》

热点排行