Please look at the sample code for getting import file info and finding out the related graphs.
void test_import_file_info() {
Worksheet wks = Project.ActiveLayer(); // Active worksheet
WorksheetPage wp = wks.GetPage(); // Workbook of the worksheet
//vector<string> vs;
//wp.GetStorageNames(vs); // Get storage names of workbook
Tree tr;
wp.GetBinaryStorage("Files", tr); // Get the imported file info
string strFile = tr.File1.Info.FilePath.strVal; // The imported file name, maybe more than one
out_str(strFile);
string strBook, strSheet;
strBook = wp.GetName(); // Get the workbook name
strSheet = wks.GetName(); // Get the worksheet name
out_str(strBook);
out_str(strSheet);
vector<string> vsGraphs; // Use to hold the graph names related to the worksheet
// GraphPage loop
foreach(GraphPage gp in Project.GraphPages) { // Loop all graphs in the project
// GraphLayer loop
foreach(GraphLayer gl in gp.Layers) { // Loop all graph layers in the graph
bool isRelated = false; // If the graph related to the worksheet
// DataPlot loop
foreach(DataPlot dp in gl.DataPlots) { // Loop all data plots in the graph layer
DataRange dr;
dp.GetDataRange(dr); // Get data range of the data plot
string strBook1, strSheet1;
dr.GetBookSheet(strBook1, strSheet1); // Get workbook and worksheet name of the data range
// Check if the data plot's workbook and worksheet are identical to
// the workbook and worksheet with imported file
if(0 == strBook1.CompareNoCase(strBook) && 0 == strSheet1.CompareNoCase(strSheet)) {
vsGraphs.Add(gp.GetName()); // Add graph name
isRelated = true; // The graph is related to the worksheet
break; // Break out the DataPlot loop
}
}
if(isRelated) {
break; // Break out the GraphLayer loop
}
}
}
for(int i = 0; i < vsGraphs.GetSize(); i++) {
out_str(vsGraphs[i]);
}
}