POI XSSF - Can't add pictures to existing xlsx file - apache-poi

At this line:
wbk.addPicture(iconData, Workbook.PICTURE_TYPE_PNG);
I get this exception:
org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException: A part with the name '/xl/media/image2.png' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]
That same line of code has worked perfectly before. If I open the xlsx file with 7zip, there is actually a image named image2.png, which is correct and is another picture added by hand with Excel. It's like it tries to add the new image with the same name as the existing image. What am I doing wrong?

I was editing a file that was saved with LibreOffice 6.1, after opening it in Excel and saving it, it worked.
Also, like #Gagravarr said, a upgrade will be better and will probably work without needing to use Excel only

Related

Why won't my Excel external links work when they work in original I copied?

I am trying to validate data moved to a new server, through reports using old and new data. I copied the old report, and then went in to change the location. Everything looks good, I used the function wizard to make sure I had no typing / syntax errors, but I still get a #VALUE error.
The query:
=SUMIFS('EXTERNAL\[Report.xlsx]RPT_DATA'!$I:$I,
'EXTERNAL\[Report.xlsx]RPT_DATA'!$B:$B,$A$3,
'EXTERNAL\[Report.xlsx]RPT_DATA'!$C:$C,$C$6,
'EXTERNAL\[Report.xlsx]RPT_DATA'!$A:$A,"ACT")
All the criteria types match to the range, I have tried it with the external file open and not, and I just can't see what I'm doing wrong, since I copied it exactly from the existing report and JUST changed the external file to a different external file in the same location (essentially, from Q:\OldSource to Q:\NewSource - these are copies of the original and new, placed in the same "working" folder).
Any hints for troubleshooting?
Seems I had a stray _.
Dagnabbit

How to attach pdf embedded in excel in outlook email with vba

I have created an embedded pdf with the insert> object > create from file> browse > display as icon function in excel.
I would like to then use the embedded pdf as an attachment for my outlook email using vba code. I have tried to use the .Attachment.Add code but it seems to fail to detech an embedded object.
Could anyone advise a correct code? Thanks!
Get the file from the source?
I don't understand why you would need to embed the.PDF object in the workbook, if you're going to be emailing it separately anyhow...
Regardless, you could just grab the actual/original .PDF to attach a copy to the email, directly from the same location from where it was embedded. (If it's not there, what happened to it?)
Another option:
As soon as you right-click the embedded object, Excel 2016 "gets ready" for you to open it by extracting it to your local temp folder. (I'm unsure whether this applies to previous versions.)
Therefore, you could programmatically right-click the embedded icon, and then check the temp folder located at the path that you'll find stored in Environ("temp"). One or more copies of your file will be located there (and it should be the 'newest' PDF).
Yet another option:
Excel's XLSM file is simply a compressed ZIP file, if you change the extension. You could programmatically make a copy of the file, changing it's extension to .ZIP.
Embedded object are stored as .BIN files within the ZIP file in the xl\embeddings\ folder. It would have to be extracted and then renamed back to a PDF. Note that this method is a little flakey and won't work with all PDF's.
More Information:
VBA Express : Save embedded PDF file as a separate PDf file
How-to-Geek : How to Extract Images, Text, and Embedded Files from Office Documents

Using modules from a specific excel file in files generated from said specific one

Tl;dwtr: General file with macro's, one to create duplicate (a Project), one to send automated mail to request stuff. Last one opens general file and is not using the duplicated in which I clicked said macro.
In my work I create loads of 'Projects' from one general excel sheet. These projects have specified information stored in them. At the moment I can make a duplicate form the general file en store this with names dates info etc.
Problem being, I wrote a macro in the general file, which uses the specified info and sends automated emails to request some type of file bases on the info. Now when I do this (use the macro inside the duplicated file) it opens the general file and uses the leftover info which is still there at the moment.
My guess is that the modules are somehow linked to a certain xls file, but im not sure nor experienced enough to figure it out. I hope some of you can help me out.

APEX: Read uploaded excel file with as_read_xlsx

As far as I understand, APEX 5.1 does not support Excel files to be loaded into tables.
I found this package that seems to make it possible to SELECT from Excel files, but it does not show how to use it with, for example, files loaded via the "File Browse" Item.
Now, I am very new to this environment, so please explain it from the beginning.
What I did is I upload the package script to the SQL workshop and executed it, without errors. But now?
APEX 5.1 doesn't support it out of the box, but you can use the EXCEL2COLLECTION plugin (available here).
It is very straightforward, just create a file browse page item with an upload button which calls an onsubmit process (e.g. CreateCollection) of type Excel2Collection[Plug In] - specify the file browse item, a collection name and the CSV separator, then you can do as you please with the data (e.g. you may want to run some validations on the data then insert it into a table where you can access it as normal).

Batch file for inserting macro's

I am trying to create a batch file as icon on desktop, that would open a specific excel file, create a macro in it and copy code from a specific txt file into it.
The reason i need this, is that the file is located on a server and the ending .xlm cannot be cahanged (should not) so i cannot save it as a macro enabled file (to store a macro in it )
Could annyone with better understanding please explain to me how to create the said code ?
Thanks in advance!
In theory it's possible by using the VBE object (https://msdn.microsoft.com/en-us/library/aa443984%28v=vs.60%29.aspx). But that's not activated by default so you can not ensure that each user is able to do that.
Better find other solutions for that problem. Can you upload .XLSB for example? Or do you have another kind of server available - for example a database server - you can use for storing the file? We use this method here for deploying our updates on AddIns and report templates for example.

Resources