Hi,
In my code i am creating a excel workbook and assigning a model name to it. This code will create a model graphic image and create a xls output with image in it.
On execution of the code it creates a file properly but an additional blank file is also created with name Reports.xls.
Can any one pls. suggest what could be wrong.
The below is the code...
Context.setProperty( Constants.PROPERTY_SHOW_OUTPUT_FILE, false );
Context.setProperty(Constants.PROPERTY_SHOW_SUCCESS_MESSAGE, false);
var gLang = Context.getSelectedLanguage();
var workbook;
var models = ArisData.getSelectedModels();
var dummyOutput = Context.createOutputObject();
main();
dummyOutput.WriteReport();
workbook.write();
function main()
{
for (mi in models)
{
var oModel = models[mi];
var workbookName =new java.lang.String(oModel.Name(gLang));
workbookName = checkName(workbookName);
workbook = Context.createExcelWorkbook(workbookName +".xls");
var sheet = workbook.createSheet(oModel.Name(gLang));
pictureOfModel(oModel,sheet);
Dialogs.MsgBox("The script was run successfully");
}
}
function checkName(workbookName)
{
workbookName = workbookName.replace("\"", "");
workbookName = workbookName.replace("\\", "");
workbookName = workbookName.replace("/", "");
workbookName = workbookName.replace("<", "");
workbookName = workbookName.replace(">", "");
workbookName = workbookName.replace("?", "");
workbookName = workbookName.replace("*", "");
workbookName = workbookName.replace("|", "");
workbookName = workbookName.replace(":", "");
return workbookName;
}
function pictureOfModel(oModel,sheet)
{
var pic = oModel.Graphic(false,false,gLang);
pic.setZoom(100);
var width = pic.getWidth(Constants.SIZE_PIXEL ) * 20 * (100.0/125.0) //twips, correction factor because of excel anomaly : (100.0/125.0)
var xCells = width / 1024;
if (xCells >255)
{
xCells = width / 2048;
}
var xTwips = width % 1024;
var height = pic.getHeight(Constants.SIZE_PIXEL ) * 20*(100.0/133.0) //twips, correction factor because of excel anomaly : \*(100.0/133.0)*/
var yCells = height / 256;
var yTwips = height % 256;
var sFileName = oModel.GUID()+".png";
pic.Save(dummyOutput,sFileName);
var data = Context.getFile(sFileName,Constants.LOCATION_OUTPUT);
sheet.setPicture ( data, Constants.XL_PICTURE_TYPE_PNG, 1, 0+xCells, 1+yCells, 0, 0, xTwips, yTwips);
Context.deleteFile(sFileName);
}
Forum: