Here's my code to retrieve attachment from Gmail message
Dim attachPart As MessagePartBody = myGMailService.Users.Messages.Attachments.Get(ProfileUsager.GoogleAccountUserName, ID, attachmentID).Execute()
Dim fileByteArray() As Byte = Convert.FromBase64String(attachPart.Data())
My problem is Convert.FromBase64String, this return:
L'entrée n'est pas une chaîne Base 64 valide, car elle contient un caractère non-Base 64, plus de deux caractères de remplissage ou un caractère non conforme parmi les caractères de remplissage.
How I can resolve this? This code is a code block I found on Google API doc.
Related
After being helped, I finally managed to apply Regex on a text to try to find some patterns.
My project consists of finding dialogues in a text written in Portuguese. In Portuguese, dialogues can be found in some ways: between dashes (- ele disse que sim-), with a dash starting the dialogue (- ele disse que sim), and in between quotation marks ("eu acho que sim").
However, as words in Portuguese can also contain dashes, such as in "viu-me" or "disse-lhe", I had make a code that takes all of this information into account.
The problem I am having is that I am getting dashes when I search for the pattern in a text.
Here is my code:
text = '''
"Para muitos é mais do que isso."
Eles chegarem em casa são e salvos
Viu-se que eles não estavam lá
'''
for d in re.finditer(r'(".+")|(^\s?-\s.+\s|-)', text, re.MULTILINE):
print(d.group())
Here is the current output:
"Para muitos é mais do que isso."
-
Fantastic, the code manages to find the dialogue in quotations, but prints a dash as well. It is as if it found that it is not a dialogue, it is just a word with an embedded dash, but still shows the dash in it.
The desired output:
"Para muitos é mais do que isso."
Just put a $ sign at the last of your regex, to denote the end.
r'(".+")|(^\s?-\s.+\s|-$)'
The reason for this is because in (^\s?-\s.+\s|-) the ending with |- is incorrect. It basically tells the regex to match \s?-\s.+\s OR a dash/hyphen. Which ends up matching the hyphen in Viu-se, since there is no notion of spaces in |-.
You'll probably also need to remove the ^ in the second group because if there are dashes in the middle of a sentence, you won't catch that.
Examples:
import re
text = '''
"Para muitos é mais do que isso."
Eles chegarem em casa são e salvos
Viu-se que eles não estavam lá
hello - More text and example - and stuff
a confusing-example-with-hyphens
Here is something else
- Start with dashes -, "quote me here"
'''
rgx = r'(".+")|(\s?-\s.+\s-)'
for d in re.finditer(rgx, text, re.MULTILINE):
print(d.group())
Gets you:
"Para muitos é mais do que isso."
- More text and example -
- Start with dashes -
"quote me here"
N.B: You could also control the exact number of spaces you want to see in case you don't want to match on multiple spaces after a dash;
rgx = r'(".+")|(\s?-\s{1}.+\s{1}-)'
This is the string
Content-Disposition: form-data; name="file"; filename="Resurrection Power+ Part 2 (El
Poder de la Resurrección) 20-3-2022.mp3"
I want to extract this
Resurrection Power+ Part 2 (El Poder de la Resurrección) 20-3-2022.mp3
i have access to an MS Access database connected with oracle (I just have permissions to view and copy information, not to edit):
And I Found some rows with value '#Error':
When I click on an error row, this warning is displayed:
I want to export this database but this warning appears again and exportation process fail.
I build a macro that can export the db but it isn't exporting ALL the data:
The result of the export is an excel file with 65534 rows and my db has 72437 rows! the are 6903 rows with value information which my macro doesn't pull into the excel file.
And I have a macro I used to pull the data from access and before this #Error rows appears, it had been working successfully:
Public Sub Bajada_OIT()
Sheets("OIT").Select
'variable para almacenar la conexion
Dim conexion As Object
'variable para almacenar los datos de la consulta al fichero access
Dim recordSet As Object
'variable con la consulta SQL
Dim consulta As String
'viarable donde almacenamos la cadena de conexión
Dim cadenaConexion As String
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'instanciamos el objeto conexion
Set conexion = CreateObject("ADODB.Connection")
'elegimos el proveedor que vamos a usar y donde se encuentra nuestra base de datos
cadenaConexion = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\SEC\COST\COST\DIT\DIT.accdb"
'consulta que haremos a la base de datos
consulta = "SELECT * FROM ADAS_PCO_OIT;"
'abrimos la conexión
conexion.Open cadenaConexion
'ejecutamos la consulta y nos traemos los resultados (recordset)
Set recordSet = conexion.Execute(consulta)
On Error Resume Next
Sheets("OIT").Range("A2").CopyFromRecordset recordSet
'Este error es debido a que la base de datos tiene filas con valores #Error que no pueden ser copiados al portapapeles.
If Err.Number = -2147467259 Then
MsgBox "La base de datos contiene datos imposibles de copiar, se ha cancelado la extracción automática."
Remove_Bajada_OIT
Exit Sub
End If
On Error GoTo 0
'cerramos el recordset
recordSet.Close
Set recordSet = Nothing
'cerramos conexion
conexion.Close
Set conexion = Nothing
MsgBox "Extraccion de Acces: ADAS_PCO_OIT (OIT) Satisfactoria.", vbInformation, "Ayuda"
End Sub
What would be the appropriate SQL query so that the errors are not displayed and the macro works again?
Or what configuration would I have to do in the database so that these errors do not appear (remember that I am not the administrator of this database)?
I Could resolve this problem doing the connection again in a new Access file:
Creating a new Access Blank desktop database.
On the External Data ribbon, choose the option "ODBC Database" That is in Import & Link Section.
Choose the source and destination area (you can specify how and where you want to store the data in the current database).
Create a New DSN File Data Source.
Select the driver for which you want to set up a data source (In my case, i use the "Oracle in OraClient12Home 1_32bit" 12.01.00.02 Driver Version)
Type the name of the file data source you want to save this connection.
Finish (Next you need to have accession privileges for enter the database if it has user/pw security).
It seems that my Data base connection had corrupted and doing this steps again has solved my problem.
I Hope this solution may solves this problem if anyone has the same trouble.
I have a comments in cell F4 from a data base in HTML and looks like this (in spanish)
<b>[2020-02-04 12:15:45]:</b> Se aguarda la llegada de materiales. Hoy llega el material a sitio. Mientras, estamos realizando auditoria en BH715.
<br>
<b>[2020-01-31 15:16:58]:</b> COMENTARIO ASIGNACION: Se reasigna a otro supervisor por vacaciones.
So... I want to clean the text deleting (html tags):
"" , ":", ""
and the result will be:
[2020-02-04 12:15:45] Se aguarda la llegada de materiales. Hoy llega
el material a sitio. Mientras, estamos realizando auditoria en BH715.
[2020-01-31 15:16:58] COMENTARIO ASIGNACION: Se reasigna a otro
supervisor por vacaciones.
The two functions nested are using:
=SUBSTITUTE(F4;CHOOSE({1\2\3};"<b>";":</b>";"<br>");"")
But, only work the first number {1... of the range.
The rest of the number it doesn't work.
official Help here:
https://support.office.com/en-us/article/use-array-constants-in-array-formulas-477443ea-5e71-4242-877d-fcae47454eb8
any advice about that ?
I am using Office 2019/265 the delimiter are semicolons in my case.
thanks a lot.
I'm new at vba and I'm trying to create a form in excel with removable lists with items taken from another excel book which contains the items I need for the list.
At the same time as I want to change the label values dynamically I made a loop For Next which change the value of the label in every turn.
I need to say before you see the code that I changed the labels name to start at 0 instead 1 so my 1st label is called label0 and not label1, I made this because I created an array with the names I need for labels.
I tried to do this:
Private Sub UserForm_Initialize()
'Declarando variables
Dim file As Workbook 'variable que contiene el libro con la tabla de los archivos
Dim var As Long 'variable que para el bucle for
Dim i As Long 'variable para el bucle for
Dim label As Variant
'Creamos una array que contenga los nombres posibles de label
label = Array("Dirección", "Empresa", "Area/Planta del suceso")
'Asignamos los valores para las variables de departamentos y empresas que abrirán los respectivos archivos que se encuentran en la ruta especificada
Set file = Workbooks.Open("C:\Users\se72497\Desktop\Departamentos.xlsx")
For var = 0 To 2
'Asigna el nombre a las etiquetas
Controls("label" & var).Caption = label(var)
'Bucle que recorre cada una de las líneas que existen en la tabla de DEPARTAMENTOS y se añaden a la lista desplegable que se especifica
For i = 2 To file.Sheets("Hoja1").Range("C2").End(xlDown).Row
direccion.AddItem file.Sheets("Hoja1").Cells(i, 3).Value
Next i
Next
file.Close
End Sub
I'm trying the variable file change every time the loop returns to the For var because when label2.caption is equal to label(2) for example needs another file than when it is label1.caption=label(0) I dont know if create another array with the files path, i suppose I can do that but if anyone know another way please let mw know.