The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Write to Excel file via COM
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

additive

Germany
109 Posts

Posted - 09/01/2011 :  10:45:04 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 8.5.1 and Service Release 1:
Operating System: Win XP

Hi,


void WriteToExcel()
{
	Object oExcel;
	oExcel = CreateObject("excel.application");
	oExcel.Visible = true;

	string strFilePathExcelTemplate = "c:\\Temp\\ExcelTemplate.xlt";
	Object oExcelWkbks, oExcelWkbk, oRange;
	Object oExcelWksh1;
	oExcelWkbks = oExcel.Workbooks;
	oExcelWkbk = oExcelWkbks.Open(strFilePathExcelTemplate);
	oExcelWksh1 = oExcelWkbk.Worksheets(1);
			
	oExcelWksh1.Cells(2,3) = "Test Cell 2, 3";  // row, col
}


worked fine using Origin 8.1. Same code does not work anymore using 8.5.1.
Strange behavior: first argument seems to be used as columns while all strings are written to first row.

How can I write to excel successfully? Usually .Value is appended to the Cells() command, but does not work with 8.1 and 8.5.1 either. .Value seems right for reading cells as OriginLab's sample (ReportCreation.c) demonstrates.

Penn

China
644 Posts

Posted - 09/01/2011 :  11:06:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

It seems that the Cells() returns a read only range. So, maybe it is not the correct way to use Cells() like this.

I have changed that line to:

oRange = oExcelWksh1.Cells(2,3);
oRange.Value = "Test Cell 2, 3";  // row, col


And that works in both 8.1 and 8.5.1.

Penn
Go to Top of Page

additive

Germany
109 Posts

Posted - 09/02/2011 :  05:38:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you, works perfect!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000