String with multiple lines of weblink images. How to display them? - string

I've got a String full of weblink image (23 links) :
listItem.text = String(item.movieimage);
If I do trace(String(item.movieimage)); the output is :
http://www.thewebsite.nc/Content/images/AFFICHES/xxx_3.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/vaiana.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/tous_scene.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/fits.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/boyfriend.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/sahara2017.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/resident_evil_final.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/raid_dingue.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/passengers2017.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/lego_batman.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/grande_muraille.jpg
http://www.thewebsite.nc/Content/images/AFFICHES/fille_brest.jpg
Know, I've got 9 UILoader on my stage.
So I would like to do
uiloader1.source = item.movieimage[1];
uiloader2.source = item.movieimage[2];
uiloader3.source = item.movieimage[3];
...etc...
How can I do that ?
Thanks

Assuming they're separated by an indent
//Put all the links in an array
var myItems:Array = listItem_txt.text.split("\n");
//You say you only have nine, so only iterate until the 9th
for (var i:int = 0; i < 9; i++)
{
//Also assuming your "uiloader" is a custom class you made with a .source property
this.getChildByName("uiloader" + i).source = myItems[i];
}

Related

EPPlus corrupt Excel file when having more than 65,530 rows

I'm running into an issue with EPPlus when there are more than 65,530 rows that have a column with a hyperlink. The example below is configured to create 65,530 rows. With this number it will create the Excel file correctly (not corrupt). Once you run it with anything over 65,530, the Excel file will be created but when you open it, Excel will report that is corrupt. Any ideas how to solve this issue?
try
{
int maxRowsToCreate = 65530; //-- no errors will be generated
//int maxRowsToCreate = 65531; //-- error will be generated. The Excel file will be created but will give an error when trying to open it.
string report = string.Format("D:\\temp\\hypelinkIssue-{0}.xlsx", maxRowsToCreate.ToString());
if (File.Exists(report))
{
File.Delete(report);
}
using (ExcelPackage pck = new ExcelPackage(new System.IO.FileInfo(report)))
{
//Add the Content sheet
var ws = pck.Workbook.Worksheets.Add("Catalog");
ws.View.ShowGridLines = true;
var namedStyle = pck.Workbook.Styles.CreateNamedStyle("HyperLink"); //This one is language dependent
namedStyle.Style.Font.UnderLine = true;
namedStyle.Style.Font.Color.SetColor(Color.Blue);
ws.Column(1).Width = 100;
int rowIndex = 0;
for (int i = 0; i < maxRowsToCreate; i++)
{
rowIndex += 1;
string fullFilePath = string.Format("D:\\temp\\{0}", Path.GetRandomFileName());
ws.Cells[rowIndex, 1].StyleName = "HyperLink";
ws.Cells[rowIndex, 1].Hyperlink = new Uri(string.Format(#"file:///{0}", fullFilePath));
ws.Cells[rowIndex, 1].Value = fullFilePath;
}
pck.Save();
}
System.Diagnostics.Process.Start(report);
}
catch (Exception ex)
{
throw ex;
}
The issue occurs when using ".Hyperlink". If instead I use ".Formula" and populate it with the "=HYPERLINK" Excel formula, it works fine. I was able to create 250k records with unique hyperlink using this approach. I did not try more than 250k but hopefully it will work fine.
Thanks for pointing me in the right direction.
/*
This only works with LESS than 65,530 hyperlinks
*/
ws.Cells[rowIndex, 1].StyleName = "HyperLink";
ws.Cells[rowIndex, 1].Hyperlink = new OfficeOpenXml.ExcelHyperLink(fullFilePath, ExcelHyperLink.UriSchemeFile);
ws.Cells[rowIndex, 1].Value = fullFilePath;
/*
This works with more that 65,530 hyperlinks
*/
string cellFormula = string.Format("=HYPERLINK(\"{0}\")", filePath);
ws.Cells[rowIndex, 1].Formula = cellFormula;
This is because Excel limits the amount of unique URLs in a file to 65,530. You should try to insert them as text, instead of a url.
For a possible solution, take a look at this answer.

How to include a for and multidimensional array in the body of php mailer?

I am using PHP Mailer.
I want to add dynamic content in php to the body but I am not being able to do it.
If I add this on the php mailer body, it works.
$mail->Body="<h3>Dados do 1º Titular</h3><ul><li><b>Nome: </b>".$titular1_name."</li><li><b>Idade: </b>".$titular1_idade."</li><li><b>Estado Civil</b>".$titular1_estado_civil."</li><li><b>Dependentes</b>".$titular1_dependentes."</li><li><b>Rendimento</b>".$titular1_rendimento."</li><li><b>Penhora</b>".$titular1_penhora."</li></ul><h3>Dados do 2º titular</h3><ul><li><b>Nome: </b>".$titular2_name."</li><li><b>Idade: </b>".$titular2_idade."</li><li><b>Estado Civil</b>".$titular2_estado_civil."</li><li><b>Dependentes</b>".$titular2_dependentes."</li><li><b>Rendimento</b>".$titular2_rendimento."</li><li><b>Penhora</b>".$titular2_penhora."</li></ul><h3>Dados de Contacto</h3><ul><li><b>Email: </b>".$titular_email."</li><li><b>Telefone</b>".$titular_phone."</li><li><b>Localidade</b>".$titular_local."</li></ul>";
But I need to add this result:
for ($y = 0; $y <= $numberOfRows; $y++){
for ($x = 0; $x < $maxData; $x++) {
array_push($row, $credito,
$capital_divida, $prestacao,
$bank, $garantias, $situacao);
echo $row[$x]."<br>";
}
array_push($fullData, $row);
}
This is my relevant code for this issue:
$row = array();
$fullData = array();
$maxData = 6;
$numberOfRows = htmlspecialchars(["numberOfRowsHTML"]);
$titular_email = htmlspecialchars($_POST["titular-email"]);
$titular_phone = htmlspecialchars($_POST["titular-phone"]);
$titular_local = htmlspecialchars($_POST["titular-local"]);
$titular_message = htmlspecialchars($_POST["titular-message"]);
$numberOfRows = htmlspecialchars(["numberOfRowsHTML"]);
$credito = htmlspecialchars(["credito"]);
$capital_divida = htmlspecialchars(["capital_div"]);
$prestacao = htmlspecialchars(["prestacao"]);
$bank = htmlspecialchars(["bank"]);
$garantias = htmlspecialchars(["garantias"]);
$situacao = htmlspecialchars(["situacao"]);
Thank you in advance for all the help
This code doesn't make any sense:
$numberOfRows = htmlspecialchars(["numberOfRowsHTML"]);
It looks like you're missing the name of an array you want to get this value from, for example:
$numberOfRows = htmlspecialchars($_POST["numberOfRowsHTML"]);
Your loop that assembles the array doesn't appear to do anything useful at all - you're getting values from the submission, then assembling an array which you don't use. It would be helpful if you could clarify what it is you're trying to do.

How to set Spinner selection by value, using CursorAdapter

I have a spinner I'm populating from the database. I want to choose which item from the list is selected by default. I need to find out what item in the list (CursorAdapter) has the value "Default Away" and set that to the selected value.
Spinner away_team_spinner = (Spinner)findViewById(R.id.away_team_spinner);
DatabaseHelper db = new DatabaseHelper(this);
Cursor team_list = db.getTeams(p_game_level);
startManagingCursor(team_list);
String[] team_name = new String[]{colTeamName};
int[] to = new int[]{android.R.id.text1};
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, team_list, team_name, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
away_team_spinner.setAdapter(adapter);
//// HERE IS WHERE MY ERRORS START ////
Log.i("NEW_GAME","Before set arrayadapter");
CursorAdapter adapter_choose = (CursorAdapter)away_team_spinner.getAdapter();
Log.i("NEW_GAME","Before set setSelection");
away_team_spinner.setSelection(adapter_choose.getPosition("Default Away"));
This is the "solution" I found by searching on this web site. However, I cannot use "getPosition" with CursorAdapter object. I tried ArrayAdapter, but then the line after "Before set arrayadapter" comment errors with "android.widget.SimpleCursorAdapter cannot be cast to android.widget.ArrayAdapter". What am I doing wrong? Thanks.
have you thought about running a for loop until you find the position then set the adapter position that way? ill draft up some code then test it, i'm doing something similar
and well this just did the trick, enjoy!
int cpos = 0;
for(int i = 0; i < simpleCursorAdapter.getCount(); i++){
cursor.moveToPosition(i);
String temp = cursor.getString((your column index, an int));
if ( temp.contentEquals(yourString)){
Log.d("TAG", "Found match");
cpos = i;
break;
}
}
spinner.setSelection(cpos);

Insert image into a specified location

I have a Google Apps script which replaces placeholders in a copy of a template document with some text by calling body.replaceText('TextA', 'TextB');.
Now I want to extend it to contain images. Does anybody have idea how to do this?
Thank you,
Andrey
EDIT: Just to make it clear what my script does. I have a Google form created in a spreadsheet. I've created a script which runs upon form submission, traverses a sheet corresponding to the form, find unprocessed rows, takes values from corresponding cells and put them into a copy of a Google document.
Some fields in the Google form are multi-line text fields, that's where '\r\r' comes from.
Here's a workaround I've come up with by now, not elegant, but it works so far:
// replace <IMG src="URL"> with the image fetched from URL
function processIMG_(Doc) {
var totalElements = Doc.getNumChildren();
for( var j = 0; j < totalElements; ++j ) {
var element = Doc.getChild(j);
var type = element.getType();
if (type =='PARAGRAPH'){
var par_text = element.getText();
var start = par_text.search(new RegExp('<IMG'));
var end = par_text.search(new RegExp('>'));
if (start==-1)
continue;
// Retrieve an image from the web.
var url = getURL_(par_text.substring(start,end));
if(url==null)
continue;
// Before image
var substr = par_text.substring(0,start);
var new_par = Doc.insertParagraph(++j, substr);
// Insert image
var resp = UrlFetchApp.fetch(url);
new_par.appendInlineImage(resp.getBlob());
// After image
var substr = par_text.substring(end+1);
Doc.insertParagraph(++j, substr);
element.removeFromParent();
j -= 2; // one - for latter increment; another one - for increment in for-loop
totalElements = Doc.getNumChildren();
}
}
}
Here is a piece of code that does (roughly) what you want.
(there are probably other ways to do that and it surely needs some enhancements but the general idea is there)
I have chosen to use '###" in the doc to mark the place where the image will be inserted, the image must be in your google drive (or more accurately in 'some' google drive ).
The code below uses a document I shared and an image I shared too so you can try it.
here is the link to the doc, don't forget to remove the image and to put a ### somewhere before testing (if ever someone has run the code before you ;-)
function analyze() { // just a name, I used it to analyse docs
var Doc = DocumentApp.openById('1INkRIviwdjMC-PVT9io5LpiiLW8VwwIfgbq2E4xvKEo');
var image = DocsList.getFileById('0B3qSFd3iikE3cF8tSTI4bWxFMGM')
var totalElements = Doc.getNumChildren();
var el=[]
for( var j = 0; j < totalElements; ++j ) {
var element = Doc.getChild(j);
var type = element.getType();
Logger.log(j+" : "+type);// to see doc's content
if (type =='PARAGRAPH'){
el[j]=element.getText()
if(el[j]=='###'){element.removeFromParent();// remove the ###
Doc.insertImage(j, image);// 'image' is the image file as blob
}
}
}
}
EDIT : for this script to work the ### string MUST be alone in its paragraph, no other character before nor after... remember that each time one forces a new line with ENTER the Document creates a new paragraph.

Adobe InDesign hangs indefinitely when I try to duplicate pages using ExtendScript

I have a very simple ExtendScript script which creates a new document out of a subset of the current active document:
var sourceDocument = app.activeDocument;
var i, j;
for(i = 0; i < sourceDocument.layers.length; i++) {
sourceDocument.layers.item(i).locked = false;
}
for(i = 0; i < sourceDocument.spreads.length; i++) {
for(j = 0; j < sourceDocument.spreads.item(i).textFrames.length; j++) {
if(sourceDocument.spreads.item(i).textFrames.item(j).locked) {
sourceDocument.spreads.item(i).textFrames.item(j).locked = false;
}
}
}
var destDocument = app.documents.add();
var firstPageIndex = 0; // In the actual script, this is chosen by the user.
var lastPageIndex = 5; // In the actual script, this is chosen by the user.
destDocument.importStyles(ImportFormat.paragraphStylesFormat, new File(sourceDocument.filePath + "/" + sourceDocument.name), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
destDocument.importStyles(ImportFormat.characterStylesFormat, new File(sourceDocument.filePath + "/" + sourceDocument.name), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
destDocument.viewPreferences.horizontalMeasurementUnits = sourceDocument.viewPreferences.horizontalMeasurementUnits;
destDocument.viewPreferences.verticalMeasurementUnits = sourceDocument.viewPreferences.verticalMeasurementUnits;
destDocument.documentPreferences.facingPages = sourceDocument.documentPreferences.facingPages;
destDocument.documentPreferences.pageHeight = sourceDocument.documentPreferences.pageHeight;
destDocument.documentPreferences.pageWidth = sourceDocument.documentPreferences.pageWidth;
destDocument.documentPreferences.pageSize = sourceDocument.documentPreferences.pageSize;
destDocument.documentPreferences.allowPageShuffle = true;
var range = sourceDocument.pages.itemByRange(firstPageIndex, lastPageIndex);
range.duplicate(LocationOptions.AFTER, destDocument.pages[destDocument.pages.length - 1]);
destDocument.pages[0].remove(); // An empty spread containing an empty page is added when the new document is created and we cannot remove it before other pages are inserted (Documents must have at least one page)
This script works perfectly on many documents. But when I execute it against one particular document (let's call it foo.indd), InDesign becomes unresponsive when executing the duplication: range.duplicate(LocationOptions.AFTER, destDocument.pages[destDocument.pages.length - 1]);. From then on, the only thing I can do is force InDesign to quit.
Is this an InDesign bug? How can I find which part of this particular document is creating the problem?
I can't really say what's wrong in your example but if indesign hangs, that might caused by the loops ( to infinity and beyond :) )
So you may try to avoid issues by outputting the loop limit to avoid InDesign re-calculation
var limit = …
for ( i = 0; i<limit ; i++)…
Additionally you could try to write info on the console to get info where InDesign is actually being stuck. So write informations on the fly on a report file and you might finally identify the issue area.
Also, you can try to interrogate every key items to see if the file has some issue.
Last but not least, try a manual export to idml of this file, re open and run again the script. Sometimes files become clunky and passing by idml fix most of them.
Give this script a try onto your probleamtic file. If it fails, please have a look at the report it should have generated onto the desktop.
http://www.loicaigon.com/downloads/cloneDocument.jsx
Loic
http://www.loicaigon.com

Resources