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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Write to Excel file via COM

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
additive Posted - 09/01/2011 : 10:45:04 AM
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.
2   L A T E S T    R E P L I E S    (Newest First)
additive Posted - 09/02/2011 : 05:38:13 AM
Thank you, works perfect!
Penn Posted - 09/01/2011 : 11:06:30 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000