Author |
Topic  |
|
reepingk
Canada
18 Posts |
Posted - 03/14/2018 : 4:51:33 PM
|
Origin 2017 w/ windows 10
#include <Origin.h>
#include <C:\Program Files\OriginLab\Origin2017\OriginC\OriginLab\FileImport.h>
void test2()
{
StringArray saFiles;
int iNumFiles = GetMultiOpenBox(saFiles, "*.z");
if( iNumFiles==0 )
{
out_str("No file was selected!");
return;
}
Page pg = Project.Pages(); // Active Page
string strPageName = pg.GetName();
// printf(strPageName + "\n");
string strFilterName = "EISunProcessed";
for(int i=0;i<iNumFiles;i++)
{
Page pg = Project.Pages(); // Active Page
string strPageName = pg.GetName();
string strFile = saFiles[i]; // strFile = file path
import_file(strPageName, i, strFile, strFilterName);
}
pg.SetName("MyBookName"); //Rename workbook (page) to "MyBookname" so I can refer back to it easier later.
GraphPage gp("Graph1");
gp.Create("EIS3"); //Create graph page using the "EIS3" template.
GraphLayer gl = gp.Layers(); //No idea what this does. Uses the current layer I suppose
WorksheetPage wksPage("MyBookName"); //I'm assuming this lets wksPage refer to the "MyBookName" workbook.
DataRange dr; //Creates a new datarange dr
foreach(Layer wks in wksPage.Layers)
{
dr.Add(wks, 4, "X"); // 5th column for X data
dr.Add(wks, 5, "Y"); // 6th column for Y data
GraphLayer gl = gp.Layers(); // Get active layer
int nPlotIndex = gl.AddPlot(dr, IDM_PLOT_SCATTER);
//out_str(wks.GetName()); //Works fine when not commented out
}
}
I'm following the example code in the manual as best I can. Most, if not all of the lines are copied and pasted directly from the manual.
I want to step through the workbook (using every sheet) and add data from columns 5 and 6 (index 4 and 5) to my graphlayer (gl).
Everything works until I get down to the "dr.Add" lines. (Meaning if I remove that block of code, the entire function compiles and runs just fine.)
Then it says that ":Error, Member function DataRange::Add not defined or does not have matching prototype."
I can only assume that wks does not contain the worksheet, therefore dr.add is failing because there IS no 4th and 5th column. But I don't know how to check or fix that. EDIT: But that can't be true, because out_str(wks.GetName()); works fine if I have it by itself inside the foreach statement. Therefore wks MUST be populated correctly or else it wouldn't return the name.
EDIT2: Either that or the column long names LITERALLY need to be "X" and "Y". I tried changing "X" and "Y" to the names of my columns that I want as X and Y, but it didn't work. If that's the case, then why the heck have the index (4 and 5) in that statement as well. Why do you need the index AND the name? That makes no sense. The names of the columns I want to plot are "Z'" and "Z''" Yes, that's Z prime and Z double prime. (Yes, I'm well aware of how annoying it is to use single quotes in strings in C.) |
Edited by - reepingk on 03/14/2018 5:17:12 PM |
|
Castiel
343 Posts |
Posted - 03/14/2018 : 10:05:31 PM
|
quote: Originally posted by reepingk
Origin 2017 w/ windows 10
Everything works until I get down to the "dr.Add" lines. (Meaning if I remove that block of code, the entire function compiles and runs just fine.)
dr.Add((Worksheet)wks, 0, "X");
dr.Add((Worksheet)wks, 1, "Y");
quote: Either that or the column long names LITERALLY need to be "X" and "Y". I tried changing "X" and "Y" to the names of my columns that I want as X and Y, but it didn't work. If that's the case, then why the heck have the index (4 and 5) in that statement as well. Why do you need the index AND the name? That makes no sense. The names of the columns I want to plot are "Z'" and "Z''" Yes, that's Z prime and Z double prime. (Yes, I'm well aware of how annoying it is to use single quotes in strings in C.)
The "X" and "Y" in dr.add() are subrange names used in DataRange. Column name/designation can be different from that.
#####
#### _\_ ________
##=-[.].]| \
#( _\ | |------|
# __| | ||||||||
\ _/ | ||||||||
.--'--'-. | | ____ |
/ __ `|__|[o__o]|
_(____nm_______ /____\____
|
 |
|
yuki_wu
896 Posts |
Posted - 03/14/2018 : 10:53:36 PM
|
Hi,
You could modify your code as below:
foreach(Layer wksly in wksPage.Layers) { DataRange dr; Worksheet wks(wksly); dr.Add(wks, 4, "X"); // 5th column for X data dr.Add(wks, 5, "Y"); // 6th column for Y data GraphLayer gl = gp.Layers(); // Get active layer int nPlotIndex = gl.AddPlot(dr, IDM_PLOT_SCATTER); //out_str(wks.GetName()); //Works fine when not commented out }
Please check the syntax of DataRange::Add again: https://www.originlab.com/doc/OriginC/ref/DataRange-Add
int Add( Datasheet & ds = NULL, int nC1 = 0, LPCSTR lpcszName = NULL, int nC2 = 0, int nR1 = 0, int nR2 = -1 )
ds should be the Worksheet or MatrixLayer.
BTW, “X” and “Y” is not the short name or long name of the columns. Actually, it is used to specify the Plot Designation, just like the “Set as X” or “Set as Y” of the right-click context menu in GUI.
Hope it helps.
Yuki OriginLab
|
 |
|
|
Topic  |
|
|
|