VS2010(VC)+OpenOffice SDK心得
设置参考:http://blog.csdn.net/douyangyang/article/details/4088841
其中JS脚本需要注意:
1、分64与32位版本,两版本注册表位置不一样
64.js
1 // OOoCpp.js 2 // 3 // OpenOffice.org 3.0 SDK C++ code generation 4 // 5 // Note: This script MUST be run from the OpenOffice.org 3.0 SDK folder: <OpenOffice.org_3.0_SDK>\sdk 6 // 7 // Copyright (c) Alain Rist 2008, 2009 8 // 9 // The use and distribution terms for this software are covered by the 10 // Common Public License 1.0 (http://opensource.org/osi3.0/licenses/cpl1.0.php) 11 // By using this software in any fashion, you are agreeing to be bound by 12 // the terms of this license. You must not remove this notice, or 13 // any other, from this software. 14 15 16 // Elevated privilege check 17 try 18 { 19 var bElevated = false; 20 var Args = WScript.Arguments; 21 for (var i = 0; i < Args.length; i++) 22 if (bElevated = (Args(i) == "/elevated")) 23 break; 24 25 var AppShell = WScript.CreateObject("Shell.Application"); 26 27 if (!bElevated && AppShell.IsRestricted("System", "EnableLUA")) 28 throw (WScript.Interactive == true) ? "Restricted" : "Elevation required."; 29 } 30 catch (e) 31 { 32 if (e == "Restricted") 33 AppShell.ShellExecute("WScript.exe", "\"" + WScript.ScriptFullName + "\"" + " /elevated", null, "RunAs"); 34 else 35 WScript.Echo("Error: " + e); 36 37 WScript.Quit(); 38 } 39 40 // OpenOffice.org 3.0 SDK C++ code generation 41 try 42 { 43 var fso = WScript.CreateObject("Scripting.FileSystemObject"); 44 var SDKBase = fso.GetParentFolderName(WScript.ScriptFullName); 45 46 var Prog = SDKBase + "\\bin\\cppumaker.exe"; 47 if (!fso.FileExists(Prog)) 48 throw(Prog +" not found!\n"); 49 50 var Dest = SDKBase + "\\includecpp"; 51 if (!fso.FolderExists(Dest)) 52 fso.CreateFolder(Dest); 53 54 var shell = WScript.CreateObject("WScript.Shell"); 55 56 var Key = "\\SOFTWARE\\Wow6432Node\\OpenOffice\.org\\Layers_\\OpenOffice.org\\3\\"; 57 var InstallKey = "HKCU" + Key; 58 59 try 60 { 61 shell.RegRead(InstallKey); 62 } 63 catch (e) 64 { 65 InstallKey = "HKLM" + Key; 66 shell.RegRead(InstallKey); 67 } 68 69 var Source1 = shell.RegRead(InstallKey + "UREINSTALLLOCATION") + "misc\\types.rdb"; 70 if (!fso.FileExists(Source1)) 71 throw(Source1 + " not found!\n"); 72 73 var Source2 = shell.RegRead(InstallKey + "BASISINSTALLLOCATION") + "Program\\offapi.rdb"; 74 if (!fso.FileExists(Source2)) 75 throw (Source2 + " not found!\n"); 76 77 shell.CurrentDirectory = shell.RegRead(InstallKey + "UREINSTALLLOCATION") + "bin" 78 var Command = Prog + " -BUCR -O \"" + Dest + "\" \"" + Source1 + "\" \"" + Source2 + "\""; 79 var exec = shell.Exec(Command); 80 81 var PropFile = SDKBase + "\\OOo.vsprops"; 82 if (fso.FileExists(PropFile)) 83 { 84 var ts = fso.OpenTextFile(PropFile, 1); 85 var Text = ts.ReadAll(); 86 ts.Close(); 87 Text = Text.replace(/Value=".+"/, "Value=\"" + SDKBase + "\""); 88 ts = fso.OpenTextFile(PropFile, 2); 89 ts.Write(Text); 90 ts.Close(); 91 shell.Popup("Path updated to " + SDKBase + " in OOo.vsprops", 10, WScript.ScriptName, 64); 92 } 93 94 while (exec.Status == 0) 95 WScript.Sleep(100); 96 97 if (exec.ExitCode) 98 WScript.Echo(Command + "\nReturned: " + exec.ExitCode); 99 else 100 { 101 WScript.Echo(Command + "\nExecuted without error."); 102 shell.Run(SDKBase); 103 } 104 } 105 106 catch (e) 107 { 108 WScript.Echo("Error " + e); 109 }
32.js,去掉“Wow6432Node”即可
那个OOo.vsprops我没用起来,直接设置的:
目录设置
要使用$(OOoSdkDir),需要添加OOoSdkDir环境变量
C/C++
LIB、 DLL
还要注意:需要自己添加
#define CPPU_ENV msci
对函数 FindInstallAndSetPath也要修改:
要加入32/64位系统判断,
注册表位置(参考js)
另外,OUString::createFromAscii 相当不好
最好这样使用:
OUString sDocUrl(sFile1);
OUString sSaveUrl(sFile2);
因为,sFile1 可能包含有非Ascii字符,这要出错的!
-------------------
Reference<XStorable> rStore (xWriterComponent, UNO_QUERY);
如果sSaveUrl格式是OO的标准格式(odl、...)好像可以直接用下面这个
rStore->storeAsURL( sSaveUrl, Sequence < ::com::sun::star::beans::PropertyValue >() );
否则要这样:
Sequence<PropertyValue> storeProps(1);
storeProps[0].Name = OUString::createFromAscii("FilterName");
storeProps[0].Value = Any( OUString::createFromAscii("MS Word 97") );
rStore->storeAsURL( sSaveUrl, storeProps);