├── .gitignore ├── .gitmodules ├── IInitializeWithFile.cs ├── IPreviewHandler.cs ├── LICENSE.txt ├── Plugin.cs ├── PreviewHandlerHost.cs ├── PreviewPanel.cs ├── PreviewPanel.xaml ├── Properties └── AssemblyInfo.cs ├── QuickLook.Plugin.Metadata.Base.config ├── QuickLook.Plugin.OfficeViewer.csproj ├── QuickLook.Plugin.OfficeViewer.sln ├── README.md └── Scripts ├── pack-zip.ps1 └── update-version.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | /*.qlplugin 332 | /GitVersion.cs 333 | /QuickLook.Plugin.Metadata.config 334 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "QuickLook.Common"] 2 | path = QuickLook.Common 3 | url = https://github.com/QL-Win/QuickLook.Common.git 4 | -------------------------------------------------------------------------------- /IInitializeWithFile.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Paddy Xu 2 | // 3 | // This file is part of QuickLook program. 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | using System.Runtime.InteropServices; 19 | 20 | namespace QuickLook.Plugin.OfficeViewer; 21 | 22 | [ComImport] 23 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 24 | [Guid("b7d14566-0509-4cce-a71f-0a554233bd9b")] 25 | internal interface IInitializeWithFile 26 | { 27 | void Initialize([MarshalAs(UnmanagedType.LPWStr)] string pszFilePath, uint grfMode); 28 | } 29 | -------------------------------------------------------------------------------- /IPreviewHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Paddy Xu 2 | // 3 | // This file is part of QuickLook program. 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | using System; 19 | using System.Drawing; 20 | using System.Runtime.InteropServices; 21 | using System.Windows.Forms; 22 | 23 | namespace QuickLook.Plugin.OfficeViewer; 24 | 25 | [ComImport] 26 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 27 | [Guid("8895b1c6-b41f-4c1c-a562-0d564250836f")] 28 | internal interface IPreviewHandler 29 | { 30 | void SetWindow(IntPtr hwnd, ref Rectangle rect); 31 | 32 | void SetRect(ref Rectangle rect); 33 | 34 | void DoPreview(); 35 | 36 | void Unload(); 37 | 38 | void SetFocus(); 39 | 40 | void QueryFocus(out IntPtr phwnd); 41 | 42 | [PreserveSig] 43 | uint TranslateAccelerator(ref Message pmsg); 44 | } 45 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Paddy Xu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Plugin.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2019 Paddy Xu 2 | // 3 | // This file is part of QuickLook program. 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | using QuickLook.Common.Plugin; 19 | using System; 20 | using System.IO; 21 | using System.Linq; 22 | using System.Windows; 23 | using System.Windows.Controls; 24 | using UnblockZoneIdentifier; 25 | 26 | namespace QuickLook.Plugin.OfficeViewer; 27 | 28 | public class Plugin : IViewer 29 | { 30 | private static readonly string[] Extensions = 31 | [ 32 | ".doc", ".docx", ".docm", 33 | ".xls", ".xlsx", ".xlsm", ".xlsb", 34 | ".vsd", ".vsdx", 35 | ".ppt", ".pptx", 36 | ".odt", ".ods", ".odp" 37 | ]; 38 | 39 | private PreviewPanel _panel; 40 | 41 | public int Priority => 0; 42 | 43 | public void Init() 44 | { 45 | } 46 | 47 | public bool CanHandle(string path) 48 | { 49 | if (Directory.Exists(path)) 50 | return false; 51 | 52 | if (Extensions.Any(path.ToLower().EndsWith)) 53 | return PreviewHandlerHost.GetPreviewHandlerGUID(path) != Guid.Empty; 54 | 55 | return false; 56 | } 57 | 58 | public void Prepare(string path, ContextObject context) 59 | { 60 | context.SetPreferredSizeFit(new Size { Width = 1200, Height = 800 }, 0.8); 61 | } 62 | 63 | public void View(string path, ContextObject context) 64 | { 65 | // MS Office interface does not allow loading of protected view (It's also possible that I haven't found a way) 66 | // Therefore, we need to predict in advance and then let users choose whether to lift the protection 67 | if (ZoneIdentifierManager.IsZoneBlocked(path)) 68 | { 69 | context.Title = $"[PROTECTED VIEW] {Path.GetFileName(path)}"; 70 | 71 | MessageBoxResult result = MessageBox.Show( 72 | """ 73 | Be careful - files from the Internet can contain viruses. 74 | The Office interface prevents loading in Protected View. 75 | 76 | Would you like OfficeViewer-Native to unblock the ZoneIdentifier of Internet? 77 | """, 78 | "PROTECTED VIEW", 79 | MessageBoxButton.YesNo, 80 | MessageBoxImage.Question 81 | ); 82 | 83 | if (result == MessageBoxResult.Yes) 84 | { 85 | _ = ZoneIdentifierManager.UnblockZone(path); 86 | } 87 | else 88 | { 89 | context.ViewerContent = new Label() 90 | { 91 | Content = "The Office interface prevents loading in Protected View.", 92 | VerticalAlignment = VerticalAlignment.Center, 93 | HorizontalAlignment = HorizontalAlignment.Center, 94 | }; 95 | context.Title = $"[PROTECTED VIEW] {Path.GetFileName(path)}"; 96 | context.IsBusy = false; 97 | return; 98 | } 99 | } 100 | 101 | _panel = new PreviewPanel(); 102 | context.ViewerContent = _panel; 103 | context.Title = Path.GetFileName(path); 104 | 105 | _panel.PreviewFile(path, context); 106 | 107 | context.IsBusy = false; 108 | } 109 | 110 | public void Cleanup() 111 | { 112 | _panel?.Dispose(); 113 | _panel = null; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /PreviewHandlerHost.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Paddy Xu 2 | // 3 | // This file is part of QuickLook program. 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | using System; 19 | using System.ComponentModel; 20 | using System.Drawing; 21 | using System.IO; 22 | using System.Runtime.InteropServices; 23 | using System.Windows.Forms; 24 | using Microsoft.Win32; 25 | 26 | namespace QuickLook.Plugin.OfficeViewer; 27 | 28 | /// 29 | /// A Windows Forms host for Preview Handlers. 30 | /// 31 | public class PreviewHandlerHost : Control 32 | { 33 | /// 34 | /// The GUID for the IShellItem interface. 35 | /// 36 | internal const string GuidIshellitem = "43826d1e-e718-42ee-bc55-a1e261c37bfe"; 37 | 38 | private IPreviewHandler _mCurrentPreviewHandler; 39 | 40 | /// 41 | /// Initialialises a new instance of the PreviewHandlerHost class. 42 | /// 43 | public PreviewHandlerHost() 44 | { 45 | Size = new Size(320, 240); 46 | } 47 | 48 | /// 49 | /// Gets the GUID of the current preview handler. 50 | /// 51 | [Browsable(false)] 52 | [ReadOnly(true)] 53 | public Guid CurrentPreviewHandler { get; private set; } = Guid.Empty; 54 | 55 | /// 56 | /// Releases the unmanaged resources used by the PreviewHandlerHost and optionally releases the managed resources. 57 | /// 58 | /// 59 | protected override void Dispose(bool disposing) 60 | { 61 | UnloadPreviewHandler(); 62 | 63 | if (_mCurrentPreviewHandler != null) 64 | { 65 | Marshal.FinalReleaseComObject(_mCurrentPreviewHandler); 66 | _mCurrentPreviewHandler = null; 67 | GC.Collect(); 68 | } 69 | 70 | base.Dispose(disposing); 71 | } 72 | 73 | /// 74 | /// Returns the GUID of the preview handler associated with the specified file. 75 | /// 76 | /// 77 | /// 78 | public static Guid GetPreviewHandlerGUID(string filename) 79 | { 80 | // open the registry key corresponding to the file extension 81 | var ext = Registry.ClassesRoot.OpenSubKey(Path.GetExtension(filename)); 82 | if (ext != null) 83 | { 84 | // open the key that indicates the GUID of the preview handler type 85 | var test = ext.OpenSubKey("shellex\\{8895b1c6-b41f-4c1c-a562-0d564250836f}"); 86 | if (test != null) return new Guid(Convert.ToString(test.GetValue(null))); 87 | 88 | // sometimes preview handlers are declared on key for the class 89 | var className = Convert.ToString(ext.GetValue(null)); 90 | if (className != null) 91 | { 92 | test = Registry.ClassesRoot.OpenSubKey( 93 | className + "\\shellex\\{8895b1c6-b41f-4c1c-a562-0d564250836f}"); 94 | if (test != null) return new Guid(Convert.ToString(test.GetValue(null))); 95 | } 96 | } 97 | 98 | return Guid.Empty; 99 | } 100 | 101 | /// 102 | /// Resizes the hosted preview handler when this PreviewHandlerHost is resized. 103 | /// 104 | /// 105 | protected override void OnResize(EventArgs e) 106 | { 107 | base.OnResize(e); 108 | 109 | var r = ClientRectangle; 110 | _mCurrentPreviewHandler?.SetRect(ref r); 111 | } 112 | 113 | /// 114 | /// Opens the specified file using the appropriate preview handler and displays the result in this PreviewHandlerHost. 115 | /// 116 | /// 117 | /// 118 | public bool Open(string path) 119 | { 120 | UnloadPreviewHandler(); 121 | 122 | if (string.IsNullOrEmpty(path)) 123 | return false; 124 | 125 | // try to get GUID for the preview handler 126 | var guid = GetPreviewHandlerGUID(path); 127 | 128 | if (guid == Guid.Empty) 129 | return false; 130 | 131 | CurrentPreviewHandler = guid; 132 | var o = Activator.CreateInstance(Type.GetTypeFromCLSID(CurrentPreviewHandler, true)); 133 | 134 | var fileInit = o as IInitializeWithFile; 135 | 136 | if (fileInit == null) 137 | return false; 138 | 139 | fileInit.Initialize(path, 0); 140 | _mCurrentPreviewHandler = o as IPreviewHandler; 141 | if (_mCurrentPreviewHandler == null) 142 | return false; 143 | 144 | if (IsDisposed) 145 | return false; 146 | 147 | // bind the preview handler to the control's bounds and preview the content 148 | var r = ClientRectangle; 149 | _mCurrentPreviewHandler.SetWindow(Handle, ref r); 150 | _mCurrentPreviewHandler.DoPreview(); 151 | 152 | return true; 153 | } 154 | 155 | /// 156 | /// Unloads the preview handler hosted in this PreviewHandlerHost and closes the file stream. 157 | /// 158 | public void UnloadPreviewHandler() 159 | { 160 | try 161 | { 162 | _mCurrentPreviewHandler?.Unload(); 163 | } 164 | catch (Exception) 165 | { 166 | // ignored 167 | } 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /PreviewPanel.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Paddy Xu 2 | // 3 | // This file is part of QuickLook program. 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | using QuickLook.Common.Plugin; 19 | using System; 20 | using System.Runtime.InteropServices; 21 | using System.Windows; 22 | using System.Windows.Forms.Integration; 23 | 24 | namespace QuickLook.Plugin.OfficeViewer; 25 | 26 | /// 27 | /// Interaction logic for PreviewPanel.xaml 28 | /// 29 | public class PreviewPanel : WindowsFormsHost, IDisposable 30 | { 31 | private PreviewHandlerHost _control; 32 | 33 | public new void Dispose() 34 | { 35 | Application.Current.Dispatcher.BeginInvoke(new Action(() => 36 | { 37 | Child = null; 38 | _control?.Dispose(); 39 | _control = null; 40 | 41 | base.Dispose(); 42 | })); 43 | } 44 | 45 | public void PreviewFile(string file, ContextObject context) 46 | { 47 | _control = new PreviewHandlerHost(); 48 | Child = _control; 49 | _control.Open(file); 50 | 51 | //SetForegroundWindow(new WindowInteropHelper(context.ViewerWindow).Handle); 52 | //SetActiveWindow(presenter.Handle); 53 | } 54 | 55 | [DllImport("user32.dll")] 56 | [return: MarshalAs(UnmanagedType.Bool)] 57 | private static extern bool SetForegroundWindow(IntPtr hWnd); 58 | 59 | [DllImport("user32.dll")] 60 | [return: MarshalAs(UnmanagedType.Bool)] 61 | private static extern bool SetActiveWindow(IntPtr hWnd); 62 | } 63 | -------------------------------------------------------------------------------- /PreviewPanel.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | using System.Windows; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("QuickLook.Plugin.OfficeViewer")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("pooi.moe")] 12 | [assembly: AssemblyProduct("QuickLook.Plugin.OfficeViewer")] 13 | [assembly: AssemblyCopyright("Copyright © Paddy Xu 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | //In order to begin building localizable applications, set 23 | //CultureYouAreCodingWith in your .csproj file 24 | //inside a . For example, if you are using US english 25 | //in your source files, set the to en-US. Then uncomment 26 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 27 | //the line below to match the UICulture setting in the project file. 28 | 29 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 30 | 31 | 32 | [assembly: ThemeInfo( 33 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 34 | //(used if a resource is not found in the page, 35 | // or application resource dictionaries) 36 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 37 | //(used if a resource is not found in the page, 38 | // app, or any theme specific resource dictionaries) 39 | )] 40 | 41 | 42 | // Version information for an assembly consists of the following four values: 43 | // 44 | // Major Version 45 | // Minor Version 46 | // Build Number 47 | // Revision 48 | // 49 | // You can specify all the values or you can default the Build and Revision Numbers 50 | // by using the '*' as shown below: 51 | //[assembly: AssemblyVersion("1.0.*")] -------------------------------------------------------------------------------- /QuickLook.Plugin.Metadata.Base.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | QuickLook.Plugin.OfficeViewer 5 | 0 6 | View Word, Excel, and PowerPoint files with MS Office and WPS Office components. 7 | -------------------------------------------------------------------------------- /QuickLook.Plugin.OfficeViewer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | net462 6 | Library 7 | QuickLook.Plugin.OfficeViewer 8 | QuickLook.Plugin.OfficeViewer 9 | true 10 | true 11 | latest 12 | false 13 | false 14 | 512 15 | false 16 | false 17 | false 18 | {9DD27AB3-C99B-4103-8BC8-B220EC399635} 19 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 20 | 4 21 | MinimumRecommendedRules.ruleset 22 | 23 | 24 | 25 | DEBUG;TRACE 26 | true 27 | full 28 | false 29 | ..\QuickLook\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.OfficeViewer 30 | 31 | 32 | 33 | TRACE 34 | false 35 | Portable 36 | true 37 | Build\Release\ 38 | 39 | 40 | 41 | DEBUG;TRACE 42 | true 43 | full 44 | false 45 | ..\QuickLook\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.OfficeViewer 46 | 47 | 48 | 49 | TRACE 50 | false 51 | Portable 52 | true 53 | Build\Release\ 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | Always 67 | 68 | 69 | 70 | 71 | 72 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95} 73 | QuickLook.Common 74 | False 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /QuickLook.Plugin.OfficeViewer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34728.123 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.OfficeViewer", "QuickLook.Plugin.OfficeViewer.csproj", "{863ECAAC-18D9-4256-A27D-0F308089FB47}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Common", "QuickLook.Common\QuickLook.Common.csproj", "{85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x86 = Debug|x86 14 | Release|Any CPU = Release|Any CPU 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|x86.ActiveCfg = Debug|x86 21 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Debug|x86.Build.0 = Debug|x86 22 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|x86.ActiveCfg = Release|x86 25 | {863ECAAC-18D9-4256-A27D-0F308089FB47}.Release|x86.Build.0 = Release|x86 26 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|x86.ActiveCfg = Debug|Any CPU 29 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Debug|x86.Build.0 = Debug|Any CPU 30 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|x86.ActiveCfg = Release|Any CPU 33 | {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95}.Release|x86.Build.0 = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | GlobalSection(ExtensibilityGlobals) = postSolution 39 | SolutionGuid = {D545EDE6-0533-4E3F-BB67-308B17E4EDAC} 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![QuickLook icon](https://user-images.githubusercontent.com/1687847/29485863-8cd61b7c-84e2-11e7-97d5-eacc2ba10d28.png) 2 | 3 | # QuickLook.Plugin.OfficeViewer (Native) 4 | 5 | This plugin renders MS Word, Excel, and PowerPoint files with native components provided by existing `Microsoft Office suite` or ~~`WPS Office`~~ (According to feedback, WPS does not support). 6 | 7 | ## Differences with [`OfficeViewer`](https://github.com/QL-Win/QuickLook.Plugin.OfficeViewer) 8 | 9 | 1. **`OfficeViewer-Native` requires an `Microsoft Office suite` or `WPS Office` installation,** whereas `OfficeViewer` does not. 10 | 2. `OfficeViewer-Native` renders documents better than ``OfficeViewer`` in most cases. 11 | 12 | ## Try out 13 | 14 | 1. Go to [Release page](https://github.com/QL-Win/QuickLook.Plugin.OfficeViewer-Native/releases) and download the latest version. 15 | 2. Make sure that you have QuickLook running in the background. Go to your Download folder, and press Spacebar on the downloaded `.qlplugin` file. 16 | 3. Click the “Install” button in the popup window. 17 | 4. Restart QuickLook. 18 | 5. Select the file and press Spacebar. 19 | 20 | ## Development 21 | 22 | 1. Clone this project. Do not forget to update submodules. 23 | 2. Build project with `Release` profile. 24 | 3. Run `Scripts\pack-zip.ps1`. 25 | 4. You should find a file named `QuickLook.Plugin.OfficeViewer.qlplugin` in the project directory. 26 | 27 | ## License 28 | 29 | MIT License. 30 | -------------------------------------------------------------------------------- /Scripts/pack-zip.ps1: -------------------------------------------------------------------------------- 1 | Remove-Item ..\QuickLook.Plugin.OfficeViewer.qlplugin -ErrorAction SilentlyContinue 2 | 3 | $files = Get-ChildItem -Path ..\Build\Release\ -Exclude *.pdb,*.xml 4 | Compress-Archive $files ..\QuickLook.Plugin.OfficeViewer.zip 5 | Move-Item ..\QuickLook.Plugin.OfficeViewer.zip ..\QuickLook.Plugin.OfficeViewer.qlplugin -------------------------------------------------------------------------------- /Scripts/update-version.ps1: -------------------------------------------------------------------------------- 1 | $tag = git describe --always --tags "--abbrev=0" 2 | $revision = git describe --always --tags 3 | 4 | $text = @" 5 | // This file is generated by update-version.ps1 6 | 7 | using System.Reflection; 8 | 9 | [assembly: AssemblyVersion("$tag")] 10 | [assembly: AssemblyInformationalVersion("$revision")] 11 | "@ 12 | 13 | $text | Out-File $PSScriptRoot\..\GitVersion.cs -Encoding utf8 14 | 15 | 16 | $xml = [xml](Get-Content $PSScriptRoot\..\QuickLook.Plugin.Metadata.Base.config) 17 | $xml.Metadata.Version="$revision" 18 | $xml.Save("$PSScriptRoot\..\QuickLook.Plugin.Metadata.config") --------------------------------------------------------------------------------