Libreoffice Base - Basic - How get data from csv file and put in the odb database? - libreoffice

I'm trying to built a macro in Libreoffice Basic that give form csv file some records and put them in an internal database built in libreoffice.
I remember that was possible in MSAccess but I have some difficult in Libreoffice Base.
the following line could use to create a connection with internal DB?
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
I found that examples
Dim DatabaseContext As Object
Dim DataSource As Object
Dim QueryDefinitions As Object
Dim QueryDefinition As Object
Dim I As Integer
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName("Customers")
QueryDefinitions = DataSource.getQueryDefinitions()
For I = 0 To QueryDefinitions.Count() - 1
QueryDefinition = QueryDefinitions(I)
MsgBox QueryDefinition.Name
Next I
but it seem no wroking. No result.
Just find a way to put what I rode on csv file inside DB

it can be achieved by following the steps below
1.Open a libre base file
2.Open the csv file you want to import
3.Copy the contents of the csv, using e.g ctr+c (if using windows operating system)
4 Go back to the opened libre base file
Click on Tables tab on the left
On the list of tables pane, right click and choose paste
A Wizard dailog box will open
Under table name, enter the name of the table you want to store the imported data
Under options, choose definition and data
10 Click next at the bottom
11 You will see the column names from the CSV by the left
Select the columns you want to import and click the right arrow button in the middle, this will move the selected columns from the left side to the right side
13 Click next at the bottom
14 Next is options to retain or change the column names, field size etc
15 Click create at the bottom
16 You will be prompted to create a primary key field, choose yes
That's all the steps needed to import all data from a CSV file into libre base file

Related

Use ContentControls to insert insert LastSavedBy Name, Date and Time information into Word form

I've set up a word form with different sections, each section to be completed by a separate person.
Each section of the form includes a combination of dropdown lists or free text fields set up using named Content controls.
At the end of each section there is field for the staff member to record their name, the date (calendar icon), and a command button with an associated macro to save the form and protect the data once that section has been completed.
While this enables the data to be protected it does not prevent person A from completing the form and entering person B's name. Note, this would not be expected, but traceability is required for regulatory purposes.
I would like to update the macro to protect the sections, save the file (currently working), and then immediately after saving, have the macro populate another field directly under the manually entered name and date with the Microsoft advanced properties of Last Saved By and the date and time. This would confirm the user.
My macro below (InsertMSSavedDetails()) will extract the Microsoft required data, but only if I manually click on the form and run the macro, and then it saves wherever I click on the form and won't save to the named ContentControl box. I'd like to automate this last step so that it is not reliant upon the user and the data is associated with particular section.
My form includes the following code:
Module
Sub ProtectFieldsSections2()
' protects Sections 1 and 2
If MsgBox("Do you want to Lock and Protect this section from further editing?", vbYesNo) = vbNo
Then Exit Sub
Dim sec As Section
Dim cc As ContentControl
Set sec = ActiveDocument.Sections(2)
For Each cc In sec.Range.ContentControls
cc.LockContents = True
Next cc
End Sub
This document:
Private Sub CommandButton2_Click()
ProtectFieldsSection1
ProtectFieldsSection2
ActiveDocument.Save
End Sub
Current code for Adding Microsoft data - which technically works, but not in the manner I need:
Sub InsertMSSavedDetails()
'
ActiveDocument.SelectContentControlsByTitle ("MSSavedDetails")
Selection.TypeText Text:="Check data: "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"LASTSAVEDBY ", PreserveFormatting:=True
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"SAVEDATE \# ""d/MM/yyyy h:mm:ss am/pm"" ", PreserveFormatting:=True
End Sub
Second issue with the above, is that it would only need to be added the once, when Sub CommandButton2_Click is first selected. If I were to update the Sub CommandButton2_Click, how would I stop if from repeating the cycle of save, insert Microsoft data, save, insert Microsoft data?
NOTE: Use of word vs PDF form. Presently, the form is used in word format, converted to PDF, and electronically signed, however this does not allow others to add their information to the remaining sections. Adobe LiveCycler has been used to design PDF forms but there were issues with maintaining images and graphs, and there were other issues experienced with the Adobe reader, so the option is to remain with word.
Thank you.
Not sure I have completely understood the problems, but
The problem with inserting the field codes LASTSAVEDBY and SAVEDATE is that unless you "lock" them, their values will always reflect the most recent save. Also, if you want the fields to go in a content control, you have to use a rich text content control.
Perhaps better to
save the document
get the underlying property values (the ones that LASTSAVEDBY and SAVEDATE display) and insert them
save the document
If you have content controls named (say)
Section1LastSavedBy
Section1SaveDate
Section2LastSavedBy
etc.
then
you know which commandbutton the user clicked so you know which section you are dealing with
your code can then look something like
Private Sub CommandButton2_Click()
ProtectFieldsSection1
ProtectFieldsSection2
With ActiveDocument
.Save
.SelectContentControlsByTitle("Section1LastSavedBy")(1).Range.Text = _
.BuiltinDocumentProperties("Last Author").Value
.SelectContentControlsByTitle("Section1SaveDate")(1).Range.Text = _
format(.BuiltinDocumentProperties("Last Save Time").Value,"D/MM/YYYY h:mm:ss am/pm")
.Save
End With
End Sub
If you want to construct the content control names programmatically based on Section number, you can.
If you want to lock the content controls against further editing, you can.
I am not sure what problem you are encountering here:
"Second issue with the above, is that it would only need to be added the once, when Sub CommandButton2_Click is first selected. If I were to update the Sub CommandButton2_Click, how would I stop if from repeating the cycle of save, insert Microsoft data, save, insert Microsoft data?"
unless you are using a Save event. If that's the problem we could revisit that part.
It's pretty difficult to stop people tampering with data in Word, but personally I would consider saving copies of these values in, e.g., a Custom XML Part (not mapped to the controls) or Document Variables - possibly also encrypt them - you can use Windows crypto APIs for that.
Incidentally, I suspect the problem you have with your existing code is that .SelectContentControlsBYTitle doesn't Select the controls in the normal Word sense. It just returns a collection of controls with that name.

copying one record to another in lightswitch

Does anyone know how to do this. I googled it but it is an old tutorial video for 2010 and doesn't seem to match up proper instructions on how to do it. I'm using 2012.
I would like to add a copy button and then click on a record , click copy and have it add a new record with the values defaulted from the one you selected.
In my app I track sales quotes. I have the ability to make and keep revisions of quotes. I do this by having a button to make a new revision that starts by copying the previous revision.
You didn't mention which language you were using. I'm using VB.NET but most of the code is very simple stuff, just declarations and assignments, so you should be able to translate it to C# very easily. Replace the keyword Me by this and you're most of the way there.
Inside my button's _Execute() code, I first make a local copy of the record to be copied:
'Create a quote object to hold the quote to be revised
Dim CurrentRev As Quote
CurrentRev = Me.qQuoteByFirm.SelectedItem
I then add a new record to the database:
'Add a new quote entity to the database
Me.qQuoteByFirm.AddNew()
And copy over the relevant information:
'Copy the necessary relevant values to the new quote
Me.qQuoteByFirm.SelectedItem.QuoteNumber = CurrentRev.QuoteNumber
Me.qQuoteByFirm.SelectedItem.RepFirm = CurrentRev.RepFirm
Me.qQuoteByFirm.SelectedItem.Customer = CurrentRev.Customer
Me.qQuoteByFirm.SelectedItem.QuoteStatus = CurrentRev.QuoteStatus
That will make a copy of the currently selected record if each value in the record is a single value. If a value has a relationship to another table and contains several records, you will need to loop through that value.
For instance, the above is just the general information for my quote. I also have a relationship to a table of quote line items. Each quote has several line items and all of these need to be copied as well. So I need to loop through each line item and create a duplicate of it as well.
'Duplicate all associate quote line items
For Each item In CurrentRev.QuoteLines
Me.qLineItemsByQuoteID.AddNew()
Me.qLineItemsByQuoteID.SelectedItem.ItemNo = item.ItemNo
Me.qLineItemsByQuoteID.SelectedItem.ProductQty = item.ProductQty
Me.qLineItemsByQuoteID.SelectedItem.Description = item.Description
Me.qLineItemsByQuoteID.SelectedItem.SellPrice = item.SellPrice
Me.qLineItemsByQuoteID.SelectedItem.PartNo = item.PartNo
Next

How to translate a label of a custom field in SugarCRM

I have created a custom field in Opportunities, but I also have to translate its label into Russian and there is no option for it in the "Edit labels" menu.
I prefer to create translated labels without Studio.
Main idea is that module string label is a value of *$mod_strings* array key which is defined in language file(s) located in modules//language/ , custom/modules//language/ and/or custom/modules/Accounts/Ext/Language/*.lang.ext.php
Thus to have an existing string in English translated into your native language manually you should do the following:
Copy your English string to be translated in browser (e.g. "Description")
Use your IDE or OS find/search function to find needed $mod_strings key that has value of the string above (e.g. *$mod_strings['LBL_DESCRIPTION']*)
Copy that key name
Change to custom/Extension/modules//Ext/Language (so called Master Directory) and create new (or append to existing) file named (in your case) ru_ru.custom.lang.php
Add a line like
$mod_strings['LBL_DESCRIPTION'] = 'Описание';
Make Quick Repair and Rebuild
Go to
Studio » Contacts » Labels,
then you can see that label and then select
'US English' or 'Russian'
from the language drop down.

How is non-standard worksheet.object created in this Excel VBA

The following VBA 6 in Excel 2000 code
Resides in a form that has text boxes, comboboxes and buttons
One of them is txtUsername, another is txtPassword
--I inherited this code
With shtName
.Unprotect "thepassword"
.range("somenamedrange").Value = cboComboBox.Value
.txtUsername.Text = txtUsername.Text
.txtPassword.Text = txtPassword.Text
...
End With
The code sets a text value for two worksheet objects that appear in the VBA Editor Object list, but are neither defined nor set anywhere else in the Excel Project. Option Explicit is used on all Microsoft Excel Objects, Forms and Modules. I can create procedures for said worksheet objects on said worksheet in the VBA Editor (e.g.,
Private Sub txtUsername_Change()
End Sub
Neither object
worksheet.txtUsername
worksheet.txtPassword
appears nor is set as a named range.
The value of both objects is only used elsewhere by specific reference worksheet.txtUsername.Text
These values do not show up in the locals window after they are set on the worksheet. They are definitely used, as the Essbase queries complete successfully using these objects.
summary:
i understand formName.txtUsername.Text (or .Value)
i do not understand a worksheet object that does not get defined nor instantiated via code
the only bright idea I had was to export the worksheet and view in a text editor, to see if my ancestors created a "custom" worksheet object the way one defines a "default property" in a class module--manually via text editor
(no mention of either property in the worksheet.cls)
Thank you.
Worksheets that are part of the Excel spreadsheet do not have to instantiated, they're part of the workbook and just "always there". If they're not visible to the user but are visible in the project browser, there could be some code in the "ThisWorkbook" section that make the sheets invisible (.visible = false) when the workbook launches.
I found that the VBA Code Cleaner cleaned "references to object definitions that cannot be found".

How to add content control in a Word 2007 document using OpenXML

I want to create a word 2007 document without using object model. So I would prefer to create it using open xml format. So far I have been able to create the document. Now I want to add a content control in it and map it to xml. Can anybody guide me regarding the same???
Anoop,
You said that you are able to creat the document using OpenXmlSdk. With that assumption, you can use the following code to create the content control to add to the Wordprocessing.Body element of your Document.
//praragraph to be added to the rich text content control
Run run = new Run(new Text("Insert any text Here") { Space = StaticTextConstants.Preserve });
Paragraph paragraph = new Paragraph(run);
SdtProperties sdtPr = new SdtProperties(
new Alias { Val = "MyContentCotrol" },
new Tag { Val = "_myContentControl" });
SdtContentBlock sdtCBlock = new SdtContentBlock(paragraph);
SdtBlock sdtBlock = new SdtBlock(sdtPr, sdtCBlock);
//add this content control to the body of the word document
WordprocessingDocument wDoc = WordprocessingDocument.Open(path, true); //path is where your word 2007 file is
Body mBody = wDoc.MainDocumentPart.Document.Body;
mBody.AppendChild(sdtBlock);
wDoc.MainDocumentPart.Document.Save();
wDoc.Dispose();
I hope this answers a part of your question. I did not understand what you ment by "Map it to XML". Did you mean to say you want to create CustomXmlBlock and add the ContentControl to it?
Have a look for the Word Content Control Toolkit on www.codeplex.com.
Here is a very brief explanation on how to do what you are attempting.
You need to have access to the developer tab on the Word ribbon. To get this working click on the Office (Round thingy) in the top left hand corner and Select Word Options at the bottom of the menu. On the first options page there is a checkbox to show the developer toolbar.
Use the developer toolbar to add the Content controls you want on the page. Click the properties button in the Content controls section of the developer bar and set the name and tag properties (I stick to naming the name and tag fields with the same name).
Save and close the word document.
Open the Content control toolkit and then open your document with the toolkit. Use the left hand pain to create some custom xml to link to your controls.
Now use the bind view to drag and drop the mappings between your custom xml and the custom controls that are displayed in the right panel of the toolkit.
You can use the openxml sdk 1.0 or 2.0 (still in ctp) to open your word document in code and access the custom xml file that is contained as part of the word document.
If you want to have a look at how your word document looks as xml. Make a copy of your word document and then rename it to say "a.zip". Double click on the zip file and then navigate the folder structure. The main content of the word document is held under the word folder in a file called "document.xml". The custom xml part of the document is held under the customXml folder and is generally found in the file named "item1.xml".
I hope this brief explanation get you up and running.