cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

write data to excel (in a row without overwriting the other rows)

sdidam
1-Visitor

write data to excel (in a row without overwriting the other rows)

Hello everyone,

I want to write data from Mathcad to an Exceldocument, where already data is saved.

The original data for example looks like this:

Excel-vorher.JPG

I want to overwrite the data in a special row. In the other rows, the data should not change. Below is my Mathcad file with 3 ways of writing data to Excel. The data should be written to the row with the number of the ID (here 3).

Mathcad.JPG

______________________________________________________________________________________________

The Variable k overwrite the first row, so this is wrong, see below.

Excel-nachher.JPG

________________________________________________________________________________________________

The Variable kk here gives the right solution, but only for ID=3, see below. So I find a third way, where I can change the ID. But if I have 1000 ID´s, this solution is very time-consuming.

Is there a better way to solve the problem?

Excel-nachher2.JPG

Thank you

Stephan

ACCEPTED SOLUTION

Accepted Solutions
MJG
18-Opal
18-Opal
(To:sdidam)

Try using the "concat" & "num2str" functions.  I didn't test it, but I think the following should work:

WRITEEXCEL(".\a.xlsx",M,concat("[3]A",num2str(ID)))

View solution in original post

2 REPLIES 2
MJG
18-Opal
18-Opal
(To:sdidam)

Try using the "concat" & "num2str" functions.  I didn't test it, but I think the following should work:

WRITEEXCEL(".\a.xlsx",M,concat("[3]A",num2str(ID)))

StuartBruff
23-Emerald III
(To:MJG)

Mark Gase wrote:

 

Try using the "concat" & "num2str" functions.  I didn't test it, but I think the following should work:

WRITEEXCEL(".\a.xlsx",M,concat("[3]A",num2str(ID)))

That will work.  There was a recent thread on a similar subject: https://community.ptc.com/t5/PTC-Mathcad/Excel-component-in-a-program/td-p/226416.

 

One of the differences between that thread and this one, is that column ID extended into AA, etc. One solution to that particular problem is to use R1C1 notation, which is simple using just num2str.  However, most people are more familiar with, and can lookup a lot easier, A1 addresses, which means converting the column number to its corresponding string.  

 

Stuart

Announcements

Top Tags