[Solved] Embed ASCII File in Spreadsheet

Creating a macro - Writing a Script - Using the API

[Solved] Embed ASCII File in Spreadsheet

Postby VBandOoffice » Fri Nov 30, 2018 12:41 pm

Hi all,
I'm doing calibrations of measurement devices. Results are saved in a spreadsheet.

Now I've the idea to embed the settings of the measurement device in this spreadsheet, as well.
This settings are a small ASCII-File.

I tried to to rename this file to .bmp and to insert it like as a picture. But this is not working.
(Rename from .ods to .zip and put the file to picture folder has not worked, too)

Does anybody knows if this is possible and how to do?

Best regards,
VBandOoffice
Last edited by VBandOoffice on Fri Dec 07, 2018 9:01 am, edited 1 time in total.
LibreOffice 5.4, Windows 7, VB.net 2010
VBandOoffice
 
Posts: 27
Joined: Tue Jul 31, 2018 10:11 am

Re: Embed ASCII File in Spreadsheet

Postby John_Ha » Fri Nov 30, 2018 1:03 pm

1. Open the ASCII file with Notepad
2. Copy all
3. Paste into Calc.

Or

1. Open the ASCII file with Notepad
2. Press Alt+PrtScr to copy Notepad window as a
3. Paste image into Calc.
4. Repeat as required.

Showing that a problem has been solved helps others searching so, if your problem is now solved, please view your first post in this thread and click the Edit button (top right in the post) and add [Solved] in front of the subject.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 7794
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Embed ASCII File in Spreadsheet

Postby VBandOoffice » Fri Nov 30, 2018 2:03 pm

Yes, this will work. But I'm looking for a solution to embed the file - not only the ASCII text.

If I don't find the solution, I'm searching for, maybe I will use this one.

Regards,
VBandOoffice
LibreOffice 5.4, Windows 7, VB.net 2010
VBandOoffice
 
Posts: 27
Joined: Tue Jul 31, 2018 10:11 am

Re: Embed ASCII File in Spreadsheet

Postby John_Ha » Fri Nov 30, 2018 2:50 pm

See Linking to external data and following on pages 270 - 282 of the Calc Guide.

This is Insert > Object > OLE Object > Further objects > tick Create from file > Navigate to some text.txt stored on my Desktop. I have the option to bring in the file or to link to it.

This is the macro I recorded while doing so: When running it It opens the window at Insert > Object > OLE Object ..., and I have to complete the selection.

Code: Select all   Expand viewCollapse view
sub zz_ole
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:InsertObject", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:InsertObject", "", 0, Array())

end sub

See also 7.11. Insert An OLE Object in Pitonyak's book which is for inserting in Writer.

Code: Select all   Expand viewCollapse view
7.11. Insert An OLE Object
The rumor is that with OpenOffice version 1.1, the following code will insert an OLE object
into a write document. The CLSID may be an external OLE object.
Listing 7.37: Insert an OLE object.
SName = "com.sun.star.text.TextEmbeddedObject"
obj = ThisComponent.createInstance(sName)
obj.CLSID = "47BBB4CB-CE4C-4E80-A591-42D9AE74950F"
obj.attach(ThisComponent.currentController().Selection.getByIndex(0))
If you select an embedded object in writer, you can access its API with:
oModel = ThisComponent.currentController().Selection.Model
This provides the same interface to the object as if you created the object by loading a
document with loadComponentFromURL
Attachments
test.ods
(16.81 KiB) Downloaded 38 times
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 7794
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Embed ASCII File in Spreadsheet

Postby VBandOoffice » Mon Dec 03, 2018 9:58 am

Hi John_Ha,
thank you very much - this looks pretty good to me. I will test it and post result (maybe this will take one or two days).

Best regards,
VBandOoffice
LibreOffice 5.4, Windows 7, VB.net 2010
VBandOoffice
 
Posts: 27
Joined: Tue Jul 31, 2018 10:11 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests