I found a problem with WRITEEXCEL. Wondering if anyone has a workaround. If I write output to Excel (let's say 1,2,3,4...20) it writes those 20 rows to excel. Then, if I change my result to (1,2,3,4...10) it writes 10 rows. However, in the excel file the data in rows 11-20 are still there from the previous result. So I have 10 rows of good data and 10 unwanted rows. If I use WRITECSV it overwrites the entire file and I only get the 10 I want. So, I can use that but is there a way to fix it for WRITEEXCEL? Is this a bug or a 'feature'? Using prime 4.0. Thanks.
Solved! Go to Solution.
I would not call it a bug but rather a feature as with WRITEEXCEL you can change parts of an existing Excel file without destroying the rest of it.
You could try to write your own routine which, if the file specified already exists, deletes it and so WRITEEXCEL would create a new file for you.
EDIT: Sorry, I just realize that you are using Prime. I have no idea how one would delete a file there. In real Mathcad I would use a scripted component (stolen from Richard) to do so.
Maybe you could try the following. using a try and catch you could first read in the content of the excel file in a Mathcad matrix. If you don't provide a range you should get all part of the first sheet containing data. Multiply this matrix by 0 an write it back using WRITEEXCEL. Not sure, bur maybe a multiplication with NaN is better - you'll have to give it a try. maybe you should fill the matrix with empty strings, not sure. Goal is to create an empty Excel worksheet (zeros are data and therefore probably not desirable).