将数据写入Excel单元时出现问题 [英] Problem writing data to excel cell
本文介绍了将数据写入Excel单元时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码在哪里出问题?
Where is the problem with this code?
using namespace Excel;
int main(array<System::String ^> ^args)
{
Excel::_ApplicationPtr pXL;
try
{
pXL.CreateInstance(L"Excel.Application");//ok, starts excel
pXL->PutVisible( 0, VARIANT_TRUE );//ok, makes excel visible
WorkbooksPtr pBooks = pXL->Workbooks;//ok
_WorkbookPtr pBook = pBooks->Add((long)xlWorksheet);//ok, Opens Sheet1
_WorksheetPtr pSheet = pXL->ActiveSheet;
pSheet->Name = "My Sheet";//ok, renames Sheet1 to My sheet
Range * pRange = pSheet->GetRange("A1","A1");//ok
pRange->PutValue2( L"1000" );//not ok, crashes with this error
/*
Attempted to read or write protected memory
*/
}
一切看起来都还不错,但是PutValue2
崩溃了. MFC中的类似代码可以正常工作.
有人可以帮我吗?
谢谢前进.
abzadeh
Everything looks okay, but PutValue2
crashes. The similar code in MFC works fine.
Can anybody help me?
Thanks in forward.
abzadeh
推荐答案
PutValue2接受数组的地址-请查看 ^ ]
内存为1000不在程序的可寻址空间中,因此会出现错误消息
PutValue2 takes the address of an array - have a look at this[^]
The memory at 1000 is not in the program''s addressable space, hence the error message
这篇关于将数据写入Excel单元时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文