Using Coldfusion 8 has anyone been able to either embed images into a excel spreadsheet (xlsx) or link them via img src?
Some background info: The cf server will pickup an excel document with product rows. Based on the product id and style etc, I be able to find or create an image that gets added as the first column into the existing excel doc.
I know coldfusion 9 has a function called SpreadsheetAddImage, unfortunately I'm on cf 8 with no chance to upgrade.
I am not sure what you are currently using to manipulate the xlsx files. However, the spreadsheet functionality in CF9 utilizes POI, which can obviously be used from CF8 as well. It just requires a little more low level code.
Pre-requisites:
Though POI is bundled with CF8, it is an old version. You need a newer version to manipulate .xlsx files. You can either use the javaLoader -OR- replace the existing jars in {cf_root}\lib folder. Note, I do not know if replacing the jars has any negative side effects.
Adding Images:
Excel does not really support <img> tags, only hyperlinks. However, you can embed images within the workbook like SpreadsheetAddImage does. As outlined in the POI's Busy Developers Guide, the basic process is:
Load the xlsx file with the WorkBookFactory
Grab the binary of each image and add it to the workbook
Anchor each image to the desired cells
Save the modified workbook to back to disk
Example:
<cfscript>
// ..
// load the xlsx file with the javaLoader
factory = loader.create("org.apache.poi.ss.usermodel.WorkbookFactory");
input = loader.create("java.io.FileInputStream").init( "c:/path/to/someFile.xlsx" );
workbook = factory.create( input );
input.close();
// get the desired sheet and load helper objects (once)
sheet = workbook.getSheet("Your Sheet Name");
patriarch = sheet.createDrawingPatriarch();
helper = workbook.getCreationHelper();
// add the image to the workbook
imageBytes = fileReadBinary( "c:/path/to/someImage.jpg" );
imageIndex = workbook.addPicture( imageBytes, workbook.PICTURE_TYPE_JPEG );
// anchor the picture to the first cell ie A1
anchor = helper.createClientAnchor();
anchor.setRow1( javacast("int", 0) ); // row of first cell (zero based)
anchor.setCol1( javacast("int", 0) ); // column of first cell (zero based)
picture = patriarch.createPicture( anchor, imageIndex );
picture.resize(); // only supported for jpg and png
// save it back to disk
outstream = loader.create("java.io.FileOutputStream").init( "c:/path/to/outFile.xlsx"" );
workbook.write( outstream );
outstream.flush();
outstream.close();
</cfscript>
New Columns
Ironically, inserting a new column is trickier than adding an image. Last I checked, POI still lacked a built in function for inserting new columns. So you would need to shift all existing cells to the right before inserting the images into the first column. The tricky part is maintaining cell formats, merged cells, etcetera.
Related
I want to get text from an image placed in a cell using Google Apps Script.
What code do I write in Google Apps Script?enter image description here
Can the cell be saved as an image and the text read?
I believe your goal is as follows.
You have a Google Spreadsheet where the images are put into the cells. In this case, the images are directly put into the cells without URLs and the built-in function. The images show some texts.
You want to retrieve the images and retrieve the texts from the images.
Unfortunately, in the current stage, there are no built-in methods for directly retrieving the images in the cells. So, in this case, I use this workaround for retrieving the images from the cells. And, in order to convert the texts from the image, Drive API is used.
When these are reflected in a sample script, it becomes as follows.
Usage:
1. Install a Google Apps Script library.
In this workaround, DocsServiceApp (Author: me) of a Google Apps Script library is used. Please install this library. You can see how to install it at here.
2. Sample script.
Please copy and paste the following script to the script editor of Spreadsheet. And, please set your sheet name.
function myFunction() {
const sheetName = "Sheet1"; // Please set your sheet name.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const spreadsheetId = ss.getId();
const ar = DocsServiceApp.openBySpreadsheetId(spreadsheetId).getSheetByName(sheetName).getImages();
const res = ar.map(({ range, image }) => {
const tempId = Drive.Files.insert({ mimeType: MimeType.GOOGLE_DOCS, title: "temp" }, image.blob).id;
const text = DocumentApp.openById(tempId).getBody().getText();
Drive.Files.remove(tempId);
return { cell: range.a1Notation, text: text.trim() };
});
console.log(res);
}
In this script, the images in the cells are retrieved using a library, and the images are converted to Google Documents. And, the text is retrieved from Google Documents.
3. Enable Drive API.
Please enable Drive API at Advanced Google services. Ref
4. Testing.
When the above script is run for your provided Spreadsheet, the following result can be seen in the log.
[
{"cell":"A1","text":"098765431 ZYX"},
{"cell":"A2","text":"1234567890 abcdef"},
{"cell":"A3","text":"098765431 ZYX"},
{"cell":"A4","text":"1234567890 abcdef"},
{"cell":"A5","text":"1234567890 abcdef"},
{"cell":"A6","text":"098765431 ZYX"},
{"cell":"A7","text":"098765431 ZYX"}
]
Note:
In this answer, I propose a simple method. When your sample Spreadsheet is used, the processing time was about 30 seconds. If your actual Spreadsheet has a lot of images, it might be required to split the cells and use the script. Please be careful about this.
References:
DocsServiceApp (Author: me)
Files: insert
Files: delete
We've just moved a Typo3 v7.6.30 Website to a new server and although the Website has started up and working as expected, when we try to upload images to content pages, they aren't displayed. When we turn debugging on, we can see that the media item has been loaded, but the 'type' property, which we would expect to be set to '2' is set to zero. Other meta data properties such as height, width and MIME type are also unset. So this explains why the image is not rendering in the template.
When we look at the 'sys_file_processedfile' table in the database, we can see that record for a 'preview' image has been created but no record for the processed image for the front end. Also, the record for the image in the 'sys_file_metadata' doesn't have any properties set.
We have run the 'Convert image formats to jpg' test in the Install too and everything shows as okay. Our 'Image Handling Settings' are set to 'Image Magick version 6 or higher' and the following options have been set in the configuration: -
[GFX][image_processing] = 1
[GFX][thumbnails] = 1
[GFX][thumbnails_png]
[GFX][gif_compress] = 1
[GFX][imagefile_ext] = gif,jpg,jpeg,tif,tiff,bmp,pcx,tga,png,pd
[GFX][gdlib] = 0
[GFX][gdlib_png] = 0
[GFX][im] = 1
[GFX][im_path] = /usr/bin/
[GFX][im_path_lzw] = /usr/bin/
[GFX][im_version_5] = im6
[GFX][im_v5effects] = 1
[GFX][im_mask_temp_ext_gif] = 1
[GFX][im_noScaleUp] = 0
[GFX][im_noFramePrepended] = 0
[GFX][im_stripProfileCommand] = +profile '*'
[GFX][im_useStripProfileByDefault] = 1
[GFX][jpg_quality] = 65
[GFX][png_truecolor] = 1
[GFX][colorspace] = sRGB
Has any one else come across this issue before? It looks as if the properties for the Processed images aren't being brought through to the front end or written to the database.
Thanks very much
If you copy an installation you might have amismatch between files in filesystem and all Information about these files in TYPO3.
Updating the storage index could show unresolved sys_file records or index other files in place of the original.
Also the metadata might fail, especially if ext:filemetadata is not installed.
Furthermore the processed images:
Some possibilities:
all images in the FE are correct, but the orignal is missing and any resizing of the images results in boken images (the hash-values for processed images and the processed images are correct, the original is missing or the sys_file record is missing)
all processed images are broken. TYPO3 has records about all processed images, but the images do not exist in filesystem. (remove all temporary images in install-tool: the records are deleted and records and images are build anew)
the folder for processed images can not be written. Normaly TYPO3 then uses the original image, which is not possible if the image has been cropped.
Bernd, thank you for your response.
We fixed the issue, php-fileinfo was not enabled on the new host. Strangely this was not detected by the install tool environment checker.
Thanks again.
Tom
I am creating a form that contains a combo box, lets say it's called 'Postcode_cb'. I want to have a unique image displayed for each of the items in that combo box. The images have to be in the same position and replace each other when the combo box is changed so that there is only ever 1 image. This has to be done without the use of file paths.
For example:
Try this way: create table [tblImg]([id], [picture]) where [id] is long and [picture] is OLE.
Insert two records with id=1 and id=2, embed corresponding images into [picture] field.
Then create stanalone form [frmImages] with rowsource [tblImg] and put 'bound object frame' with control source [picture].
Put [frmImages] as sub form at your main form.
Set LinkMasterFields to [Postcode_cb] and LinkChildFields to [id].
I have something like this on a database that gives out star rating of hotels. As you browse through the hotels it displays actual stars depending on the rating. The way that i did this was placed all the images in 1 spot (Placing them on top of one another) Give each image a name. and set them all to visible = no.
Example Img1, Img2 etc. until all images have a name.
Then open Visual basic and create a sub called Private Sub Form_Current() if you don't already have one. Then under this sub use the following Code
Forms![FormName]![ComboBoxName].SetFocus
Select Case Forms![FormName]![ComboBoxName].Text
Case Is = ""
Forms![FormName]!img1.Visible = False
Forms![FormName]!img2.Visible = False
Case Is = "1"
Forms![FormName]!img1.Visible = True
Case Is = "2"
Forms![FormName]!img2.Visible = True
End Select
This is only good if you only have something like 5 to 10 images anything more would be a lot harder to deal with in this way.
There maybe other ways people can suggest i found this the most easiest for my needs.
I a working on a simple window phone application. In which I have two filed Name and Images.
I want to save this item and want to view all saved data.
Now My query How to select images to save? and How to save images and also get images to view.
I also used PhotoChooserTask but How to save selected image and how to get saved images?
I know about how to save image file in Isolated storage. But how to save selected images and get all data?
Thanks,
Hitesh.
Thanks for your reply. I knew about photoChooserTask. I also save my image file in isolated storage. But I dont know what is the images path to save images path in database and how to display all those images in datagrid. I have a table which have fields like ID, Name and Image path. I dont know what to save in imagepath filed if I saved image in isolated storage and how to display all data in datagrid.I used following code to save data into database. IN below code please correct the image path if I was wrong.
CategoryVO newCategory = new CategoryVO()
{
Name = txtCategoryName.Text,
ImagePath = txtCategoryName.Text.Trim() + ".jpg"
};
Expdb.Category.InsertOnSubmit(newCategory);
Expdb.SubmitChanges();
Using the PhotoChooserTask you can actually launch the photo chooser application and handle the selected image.
If you want to integrate this in your application, create the instance of the PhotoChooserTask and call the Show() method. If you want to handle the user’s selection, register the Completed event which will give you handle of the chosen photo.
var photoChooserTask = new PhotoChooserTask();
photoChooserTask.Completed += PhotoChooserTaskCompleted;
photoChooserTask.Show();
In the completed event implementation, you can get the chosen image as PhotoResult and set the image to your Image control or can use it in other places.
void PhotoChooserTaskCompleted(object sender, PhotoResult e)
{
switch (e.TaskResult)
{
case TaskResult.OK:
imageChooser.Source = new BitmapImage(new Uri(e.OriginalFileName));
break;
}
}
Source: http://www.codeproject.com/Articles/350126/How-to-use-the-PhotoChooserTask-to-Launch-the-Medi
Is it possible to use System.Drawing.Image in an RDLC Image Control?
All I have been reading were 3 methods:
database
embeded resource
external file
Thank you thank you.
EDIT:
Following up from this .NET or C# library for CGM (Computer Graphics Metafile) format? I now got the image in System.Drawing.Image format and want to display it as part of the report (as an image) --- that's what I want to do.
Not sure if this is what you are looking for, but if you have an image in code and you want to show it in the report, create a wrapper object that has a property that returns the image as a byte array and give then an instance of this wrapper-class with the valid image to the report as a ReportDataSource.
Something like:
ReportDataSource logoDataSource = new ReportDataSource();
logoDataSource.Name = "LogoDS";
logoDataSource.Value = new List<LogoWrapper>() { yourLogoWrapper };
localReport.DataSources.Add(logoDS);
In the report you then you can the image as it were from the database
=First(Fields!LogoByteArrayProperty.Value, "LogoDS")
The wrapper looks something like:
class LogoWrapper{
...
public byte[] LogoByteArrayProperty{
get{
// Return here the image data
}
}
}
I use this quite often. It has the advantage that I don't have to add the image to the db or add it as a resource of every report. And furthermore, the app can say which image should be used.
Please note, the given image format must be known from the rdlc-engine.
The last question would be, how to convert a system.drawing.image to a byte array. I work with WPF and therefore, I dont known. But I'm sure google will respond to this question very reliable.
You Can use the 'Database' Source Option along with Parameters to Dynamically set Image Source from Byte Arrays.
Code Behind:
var param2 = new ReportParameter()
{
Name = "CompanyLogo",
Values = { Convert.ToBase64String(*ByteArrayImageObject*) }
};
ReportViewer1.LocalReport.SetParameters(param2);
rdlc File:
1- Add Text Parameters 'CompanyLogo' and 'MIMEType'
2- Set the Value Property of the Image to =System.Convert.FromBase64String(Parameters!CompanyLogo.Value)
3- Set MIME Type Property to
=Parameters!MIMEType.Value
4- Use 'Database' As Source
How can I render a PNG image (as a memory stream) onto a .NET ReportViewer report surface
i am not quite sure what do you want to do with this but in general it is not possible.Image Control is just a image holder in the RDLC files.These 3 options specify the location from where the image control takes the image which to display from- database, embeded resource or external file. If you give me more info on what do you want to achieve i can give you some kind of solution.
Best Regards,
Iordan