Excel (XLS) to CSV with UTF-8 - sql

I have read the following advice for converting UTF-8 encoded(Hebrew) XLS to CSV via Google Docs, and it worked. When I open the CSV in Sublime2 with UTF8 encoding the Hebrew is showing correctly. But then, when I try to import the Data to My DB using SQLyog, after making sure that both my target table and the import definitions are set to UTF8, I get gibberish, like: מדרשות
Where did I go wrong?

The best way to export from excel to csv is:
Open the excel file and click on "Save as..."
Insert a name and then in "Save as File Type" select "CSV (Comma delimited)"
Then, click on "Tools" and select "Web Options"
Go to "Encoding", under the option "Save this document as" select "Unicode (UTF-8)".
Listo! I couldn't leave the answer in the proper question : (
Original post found> eHow(spanish)
Some images of this.

In Microsoft Excel, open the *.xlsx file.
Select Menu | Save As.
Enter any name for your file.
Under "Save as type," select Unicode Text.
Click Save.
Open your saved file in Microsoft Notepad.
Replace all tab characters with commas (",").
Select a tab character (select and copy the space between two column headers)
Open the "Find and Replace" window (Press Ctrl+H) and replace all tab characters with comma .
Click Save As.
Name the file, and change the Encoding: to UTF-8.
Change the file extension from ".txt" to ".csv".
Click Save.
Open the .csv file in Excel to view your data.
source: https://help.salesforce.com/articleView?id=000003837&type=1

For development purpose, I need to change regularly an Excel file and to generate a "CSV" file that is a text file where column's elements are separated by TAB character.
To facilitate my work, I have created following VBS script
'***********************************************************************
'* file: SaveAs.CSV.bat
'***********************************************************************
sInputFile = Wscript.Arguments(0)
WScript.Echo "Excel input file: " & sInputFile
Set ex = CreateObject("Excel.Application")
Set wb = ex.Workbooks.Open(sInputFile)
ex.Application.DisplayAlerts = False
'https://learn.microsoft.com/en-us/office/vba/api/office.msoencoding
wb.WebOptions.Encoding = 28591
ex.Application.DefaultWebOptions.Encoding = 28591
'https://learn.microsoft.com/en-us/office/vba/api/excel.xlfileformat
sOutputFile = Replace(sInputFile & "*",".xlsx*",".txt")
ex.Worksheets(1).SaveAs sOutputFile, 20
ex.ActiveWorkbook.Close
ex.Application.Quit
WScript.Echo "CSV file has been created."
WScript.Quit
To start "CSV" file creation for a specific XLSX file, I have created following BAT file
cscript SaveAs.CSV.vbs "D:\Documents\+Informatique\Application\#Visual Basic.NET\DrawPlanUnifilaire\Plan-Unifilaire.xlsx"
pause
So, I only click on BAT file and a TXT tab separated file is automatically generated from first sheet in XLSX file.
The UNICODE UTF8 characters contained in XLSX file (éèàüäù) are correctly converted to Windows ANSI characters.

The solution I came up with was skipping the conversion from CSV to SQL using RegExp. Something like:
FIND: "(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)","(.*)"
REPLACE: INSERT INTO aminadav VALUES (NULL,$1,"$2",$3,"$4","$5","$6","$7","$8","$9","$10");

Related

Documents.Open Format: .mht in word

Problem: Word sometimes doesn't choose "Single File Web Page" format automatically for .mht files.
Description:
When opening files in Word application there is an option to select file conversion format:
For the .mht files to be correctly decoded/viewed i noticed that selecting format "Single File Web Page" works perfect.
Is it possible to achieve this programmatically? Lets say I would like to open the .mht file in word application, and use word's converter to treat it as a "Single File Web Page" file.
So far I have found that Documents.Open method (https://learn.microsoft.com/en-us/office/vba/api/word.documents.open) accepts parameter "Format". But it seem like it doesn't have the format I need. The closest I see is wdOpenFormatWebPages(7), but it is not the same as "Single File Web Page"
https://learn.microsoft.com/en-us/office/vba/api/word.wdopenformat
VB:
Documents.Open FileName:="C:\test.mht", format:=7
C#:
Application app = new Application();
Document document = app.Documents.Open(FileName: #"C:\test.mht", Format: 7);
Good day community,
Microsoft support have already document this .mht issue and offer a simple solution. I use it to get quick 'highly detail QA and training document in Word format' from PSR.exe recording (also provide in all Windows terminal since Win7). I have a conversion script to do it in batch for my tester/trainer at my compagny. With the right title and the command 'dir /b', it also build a table of content to help research for newly employés :
Ref : https://support.microsoft.com/en-us/topic/the-confirmconversions-property-in-macro-changes-the-confirm-conversion-at-open-option-in-word-6f16c1db-4cb8-2727-dc4f-fdf6ef112ff5
Sub MyDocumentOpenMacro()
Dim x As Integer
' Set x equal to the current setting of the Confirm conversion at Open
' option before opening your file.
x = Application.Options.ConfirmConversions
' Open your file.
Documents.Open "C:\My Documents\Address.txt", ConfirmConversions:=False
' Use a conditional statement to set the Confirm conversion at Open
' option back to its setting (value of x) before opening your file.
If x = "0" Then
Application.Options.ConfirmConversions = False
Else
Application.Options.ConfirmConversions = True
End If
End Sub

Export Access Query WITHOUT Formatting

Relatively simple, but I can't seem to work it out. I want to export a query from access into a .csv (tab or comma delimited). When I do it manually through the wizard it works fine. But when I do it via vba, it comes complete with dash formatting that looks like the borders in the table!
I tried two methods and got the same results
DoCmd.OutputTo acOutputQuery, "Qry_GRADE", "MS-DOSText(*.txt)",_
"grade.csv", True, *ExportSpec*, , acExportQualityScreen
I used it with or without "ExportSpec", which is a specification I created when exporting manually.
This is the second method:
Dim testSQL As String
Dim qd As DAO.QueryDef
testSQL = "SELECT * FROM Qry_Grade"
Set qd = db.CreateQueryDef("tmpExport", testSQL)
DoCmd.TransferText acExportDelim, , "tmpExport",_
"C:\Users\Databoe\Documents\KidsTV\grade.csv"
db.QueryDefs.Delete "tmpExport"
This is a solution I've found which seems like overkill
And this is what the output looks like:
You can see it's not actually split any of the columns when opening the file in excel and that every second line is just a string of "-"'s
What about DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, myQueryName, myExportFileName, True for direct excel file export.
I tried your approaches, but I only get formated text with your first try DoCmd.OutputTo acOutputQuery, "Qry_GRADE", "MS-DOSText(*.txt)",_
"grade.csv", True, *ExportSpec*, , acExportQualityScreen which is as expected because it's a text export not csv.
With your second method I always get an excel compatible result. Maybe you have an error trap that hides an error and the first grade.csv is not overwritten. Use a different filename for the second method to prevent that.
Found a second trap. You don't specify full file path in first method, but in second. If C:\Users\Databoe\Documents\KidsTV is not your default document path, you have 2 grade.csv in different folders, but you maybe think that you only have one that gets overwritten.
I just ran into this problem myself, and found a great work around. It doesn't save as a .csv, but you can save as a comma delimited .txt file.
Use the export wizard on the External Data tab to export your query as a .txt file without formatting.
Once the file is exported you get a dialogue box asking if you want to save export steps. Click the box and save the export.
There is an action available in the Macro wizard called "Run Saved Import/Export." Select this action and choose your saved export from the dropdown menu.
Very frustrating that even now I cant seem to make Access export a simple csv file. I do not know why they think I need pretty formatting. Try this: open Excel, Click Get Data, From Database, From MicroSoft Access Database. Select the Access Database you wish to export from. Select the table/query we want saved as an csv. This will set up a link to this table. Once imported, save the Excel file to an csv file.

Would like to run an Excel macro with drag and drop

I have a macro that asks the user to choose an excel file and then outputs two text files based on the data.
I am looking for a way to just drop the excel file onto the macro file and have it process without the need for opening the macro file, a command button, an open file dialog, etc. I would like to drop the file on the other file and just have the two text files output.
I saw something that looked promising using a VBS file, but was unable to get it to work.
Here's the bare bones of what you need to do:
Wscript.echo "Begin..." 'just letting you know it's working
Set objArgs = Wscript.Arguments 'capture arguments; arg 0 is the name of the dropped file
Wscript.echo "The file name you dropped is:" & objArgs(0)
'DO STUFF TO THE FILE HERE
Wscript.echo "...Finished" 'all done
Save this to a file with a "vbs" extension.
Drag and drop a file onto it.
If your Windows file associations are properly setup,
you'll see this output a message for each of the wscript.echo
lines.

VBA Dialogue prevent user from changing extension FileFilter option

Say I have a directory with multiple file types, and that I have already set the file filter to show only CSV files
paths = Application.GetOpenFilename("Comma Separated Values (*.csv),*.csv", _
MultiSelect:=True)
The above code does apply the filter correctly.
Now when I put an any filter text in the file name editbox and hit open/enter, the file extension filter no longer works/gets reset to the user's filter.
This means that if I have files called test.doc and test.csv in the same directory and type in test* in the open file dialog editbox, both the Word document and the CSV file will show as selectable.
Is this a bug and is there a way around this? That is, I want the user-defined filter to be an addition to the predefined filter.
I think I understand what you're asking. I knew I had this one laying around somewhere.
This is without muti select:
fileOpen = Application.GetOpenFilename("Text Files (*.csv),*.csv,Word Files (*.doc),*.doc")
This is with Muti select plus title:
fileOpen = Application.GetOpenFilename("Text Files (*.csv),*.csv,Word Files (*.doc),*.doc", 1, "Pick Your CSV File", , True)
Hope that helps!

Extract data from PDF file with VB.Net

I'm trying to pull some data from a large PDF file in VB.Net I found the following code online, but it's not helping:
Sub PrintPDF (strPDFFileName as string)
Dim sAdobeReader as String
'This is the full path to the Adobe Reader or Acrobat application on your computer
sAdobeReader = "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe"
RetVal = Shell(sAdobeReader & "/P" & Chr(34) & sStrPDFFileName & Chr(34), 0)
End Sub
I'm really lost. Any ideas?
/P will just display load the file and display the Print dialog - dead end.
You will probably need a library of some sort to get to the contents of the PDF.
If the file has a very simple structure you maybe able to extract the data just by reading the bytes. See if you can open it with a file like Notepad++ and see the contents.
BTW VS2010 has several editors for looking at/editing files:
File, Open File... pick the file then use the dropdown on the Open button.