没有讨论为什么我需要OLE ..我需要将一个托管的C++自定义控件嵌入到MS Word 2007中(2003年也会很好).
我似乎需要做一些类似于实现接口的事情.但是最新的教程很难找到.
我已经阅读了关于OLE的维基百科文章.我可以谷歌的所有信息都是古老的(1994)和/或VB中心(4.0-6.0).任何对当前时间有意义的东西......链接/书籍请发布.
谢谢阅读..
我正在使用CoCreateInstance实例化本地COM服务器.有时,提供服务器的应用程序需要很长时间才能启动.发生这种情况时,Windows会弹出如下对话框:
服务器繁忙
由于其他程序正忙,因此无法完成操作.选择"切换到"以激活忙碌程序并更正问题.
[切换到...] [重试] [取消]
我在Application对象OleRequestPendingTimeout上发现了一个Visual Basic属性,可用于控制此对话框出现之前的时间.我找不到任何关于这个的好文档或者从C++中有用的等价文档.谁能指出我正确的方向?
我有一个基于Web的Perl Win32 :: OLE脚本,它在服务器端使用Excel.多年来,它一直在运行Excel2000的Win2000服务器上愉快地工作.我们最近升级到Win2003/Excel2003,现在我从脚本中收到以下错误:
Win32::OLE(0.1709) error 0x80070005: "Access is denied" at create_worksheet_lib.plx line 639
eval {...} called at create_worksheet_lib.plx line 639
Run Code Online (Sandbox Code Playgroud)
第639行是:
$Excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Excel";
Run Code Online (Sandbox Code Playgroud)
Perl似乎无法访问Excel.任何Windows专家都可以帮助解决问题吗?
考虑下面给出的C#中与自动化兼容的COM库.它遵循一个常见的COM模式,即有一个可见的工厂coclass FooFactory实现ICreateFoos,它创建一个IFoo类型的对象.FooFactory是类型库中唯一的 coclass.(工厂模式对COM特别有用,因为它不允许参数化构造函数).
在下面的代码中,我发现我无法从jscript 访问返回的IFoo接口,除非我使FooImpl类ComVisible(通过取消注释注释行;这使它在类型库中显示为coclass).从VBscript访问它没有这样的问题.
也就是说,我可以运行这个VBScript:
set ff = CreateObject("jstest.FooFactory")
set foo = ff.CreateFoo(0)
foo.Foo
Run Code Online (Sandbox Code Playgroud)
但这个功能相同的 JScript失败,错误"C:\ temp\jstest\jstest.js(4,1)Microsoft JScript运行时错误:'foo'为null或不是对象":
var ff = new ActiveXObject("jstest.FooFactory");
var foo = ff.CreateFoo(0)
//WScript.Stdout.WriteLine(null==foo)
foo.Foo();
Run Code Online (Sandbox Code Playgroud)
如果我取消注释该行,我可以看到null == foo为false.
为什么会这样?这是一个错误吗?请注意,我认为这是一个问题,是JScript和C#/ .net特定实现(可能是IDispatch)的组合,因为我有其他类似的COM服务器 - 用C++实现 - 不会从JScript中出现这个问题.
如果我在下面的代码中取消注释注释行,使得FooImpl作为coclass可见,那么问题就会消失 - 但我特别不希望这样做,因为我不想暴露实现细节.一个解决方法似乎是使FooImpl ComVisible,但标记其构造函数内部,这可以防止客户端能够CoCreate它,但这并不优雅.
我正在使用Visual Studio 2005,.net 2在WinXP SP3上运行,并且能够在VirtualBox上完全全新安装TinyXP(都使用Windows Script Host 5.7)以及使用Windows 7 Ultimate进行重现.net SDKs 2.0,3.0,3.5和4.0(WSH 5.8).所有操作系统都是32位.
库代码:
using System;
using System.Runtime.InteropServices;
[assembly: ComVisible(false)]
namespace jstest
{
[ComVisible(true)]
public interface ICreateFoos
{
IFoo CreateFoo(int …Run Code Online (Sandbox Code Playgroud) 这是在Delphi中完成的自定义命名空间处理程序,用于将文件加载到webbrowser组件中.
Datastream:IStream; var F: TFileStream; Dummy: INT64; begin F:=TFileStream.Create(strfilename fmOpenRead); CreateStreamOnHGlobal(0, True, DataStream); TOleStream.Create(DataStream).CopyFrom(F, F.Size); DataStream.Seek(0, STREAM_SEEK_SET, Dummy); TotalSize := F.Size; F.Free; end;
问题是Fastmm4在程序结束时出现内存泄漏错误并且说没有释放TOleStream.我如何释放它?如果我把TOleStream放在变量中并像这样分配
var TOS:TOleStream; TOS:=TOleStream.Create(DataStream) TOS.CopyFrom(F, F.Size); .. TOS.Free; End;
当我释放TOS变量时,我得到一个错误(EAccessViolation指向ComObj中的TComObject.ObjRelease).非常感谢您的意见和帮助.这个问题一直困扰着我一段时间.
我也想知道它是否可能是FastMM4的东西?它会提供虚假信息吗?在一些代码如下.TOLEStream通常如何被释放?
f.SaveToStream(TOleStream.Create(DataStream));
有没有办法在不使用TFileStream的情况下将数据发送到数据流?
嗨,Remy,您可以在这里找到一个带有fastmm和问题过程的命名空间处理程序的工作演示项目:http://mode5.webs.com/namespace.7z 当项目加载时,单击按钮以加载命名空间处理程序文件.退出时,应该得到fastmm错误.亲切的问候,
foreach my $row (1..$end)
{
foreach my $col (3..27 )
{
# skip empty cells
next unless defined
$worksheet->Cells($row,$col)->{'Value'};
# print out the contents of a cell
$var = $worksheet->Cells($row,$col)->{'Value'};
push @dates, $var;
print $var; #this prints the value just fine
}
}
my %hash;
$hash{'first'} = \@dates;
print Dumper \%hash; #This prints object information
Run Code Online (Sandbox Code Playgroud)
我使用模块OLE for Perl和我从工作表中获得的每个值并打印$ var然后我得到了预期的值,但是当我把所有内容放入哈希时它打印:
'first' => [
bless( do{\(my $o = 15375916)}, 'OLE::Variant'),
bless( do{\(my $o = 15372208)}, 'OLE::Variant'),
Run Code Online (Sandbox Code Playgroud)
等等.我一定不明白哈希的事情,因为我真的很难过.
我有一个Excel文件,我想在工作表中更新多行.所以我写这段代码:
OleDbConnection cn = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + serverPath + ";Extended Properties = Excel 8.0;");
try
{
strUpd = "";
strUpd += "update [Data14City$] set B_1_1 = 5 ,B_1_2 = 26 ,B_1_3 = 44 ,B_1_4 = 8 where id = 1 ";
strUpd += " update [Data14City$] set B_1_1 = 0 ,B_1_2 = 8 ,B_1_3 = 17 ,B_1_4 = 0 where id = 2";
cn.Open();
OleDbCommand cmdInsert = new OleDbCommand(strUpd, cn);
cmdInsert.ExecuteNonQuery();
cn.Close();
}
catch …Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试在电子表格中动态创建Web浏览器然后使用它,但WebBrowser功能似乎不起作用
以下是我创建WebBrowser的方法
Set myWebBrowser = Sheets("test").OLEObjects.Add(ClassType:="Shell.Explorer.2", Link:=False, DisplayAsIcon:=False, left:=147, top:=60.75, width:=141, height:=96)
Run Code Online (Sandbox Code Playgroud)
这会奏效
myWebBrowser.top = 10
Run Code Online (Sandbox Code Playgroud)
但这会给我一个错误
myWebBrowser.Navigate ("about:blank")
Run Code Online (Sandbox Code Playgroud)
关于我应该做什么的任何想法都要感谢你
更新:
这也不起作用并给出错误:
myWebBrowser.Object.Document.body.Scroll = "no"
myWebBrowser.Object.Silent = True
myWebBrowser.Object.Navigate ("about:blank")
While myWebBrowser.Object.ReadyState <> READYSTATE_COMPLETE
Application.Wait (Now + TimeValue("0:00:01"))
Wend
myWebBrowser.Object.Refresh
Run Code Online (Sandbox Code Playgroud)
更新2(几乎在那里):
现在我需要一种方法来删除Sheet2.Activate Sheet1.Activate
Sheet2.Activate
Sheet1.Activate
Set wb = myWebBrowser.Object
With wb
.Silent = True
.Navigate "about:blank"
Do While .ReadyState <> READYSTATE_COMPLETE
Application.Wait (Now + TimeValue("0:00:01"))
Loop
.Document.Open "text/html"
Do While .ReadyState <> READYSTATE_COMPLETE
Application.Wait (Now + TimeValue("0:00:01"))
Loop
.Document.write …Run Code Online (Sandbox Code Playgroud) 我有一个子程序,通常需要1秒才能运行.有时,它可以无限运行.如果子程序花费的时间太长(> 10秒)并且忽略该子程序的运行,我想继续执行代码.这是我到目前为止使用的警报.
use Win32::OLE;
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 10; # schedule alarm in 10 seconds
&do_the_subroutine;
alarm 0; # cancel the alarm
};
if ($@) {
$error_string .= $script;
#Do something else if the subroutine took too long.
}
do_the_subroutine{
# use existing instance if Excel is already running
eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')};
die "Excel not installed" if $@;
unless (defined $ex) {
$ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
or die "Oops, cannot start …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails 5.我想从Word文档(.doc)中获取文本,所以我正在使用此代码
text = nil
MSWordDoc::Extractor.load(file_location) do |ctl00_MainContent_List1_grdData|
text = contents.whole_contents
end
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误.我的Gemfile中有这个gem
gem 'msworddoc-extractor'
Run Code Online (Sandbox Code Playgroud)
要从Word文档中获取内容还需要做些什么?如果我能.docx像文件一样对文件应用相同的代码,那就太好了.doc.
/Users/davea/.rvm/gems/ruby-2.4.0/gems/ruby-ole-1.2.12/lib/ole/support.rb:201: warning: constant ::Fixnum is deprecated
Ole::Storage::FormatError: OLE2 signature is invalid
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:378:in `validate!'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:370:in `initialize'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:112:in `new'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:112:in `load'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:79:in `initialize'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:85:in `new'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/ruby-ole-1.2.12/lib/ole/storage/base.rb:85:in `open'
from /Users/davea/.rvm/gems/ruby-2.4.0/gems/msworddoc-extractor-0.2.0/lib/msworddoc/extractor.rb:11:in `load'
from /Users/davea/Documents/workspace/myproject/app/services/msword_processor_service.rb:12:in `pre_process_data'
from /Users/davea/Documents/workspace/myproject/app/services/abstract_import_service.rb:88:in `process_race_data'
from (irb):2
from /Users/davea/.rvm/gems/ruby-2.4.0@global/gems/railties-5.0.1/lib/rails/commands/console.rb:65:in `start'
from /Users/davea/.rvm/gems/ruby-2.4.0@global/gems/railties-5.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/davea/.rvm/gems/ruby-2.4.0@global/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/davea/.rvm/gems/ruby-2.4.0@global/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/davea/.rvm/gems/ruby-2.4.0@global/gems/railties-5.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from …Run Code Online (Sandbox Code Playgroud)