DoCmd.TransferText where delimiter is semicolon and decimal is comma - excel

I'm trying to import a csv file with:
Dim appAccess As Access.Application
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase (databasePath)
appAccess.DoCmd.TransferText transferType:=acImportDelim, tableName:=dbTableName, Filename:=strPath, hasFieldNames:=True
I'm using a German machine, where the standard delimiter is ; and the standard decimal-separator is ,.
If I use those separators, I get an error (the data is not separated correctly).
If I change the separator in the csv file to ,and the decimal-separator to ., the data is loaded in the database, but the . is ignored and numeric values therefore aren't imported correctly.
I don't have the option, to create an import scheme in Access manually. Is there a way, to do this with VBA?
I created a Schema.ini file, which looks like this:
[tempfile.csv]
Format=Delimited(;)
ColNameHeader=True
DecimalSymbol=","
I saved it in the same folder where the csv file is located.
I still get a Runtime-Error, saying field1;field2;... is not a header in the target table. So I'm guessing, the method didn't use ; as a delimiter.

If you have a look at the documentation of the DoCmd.TransferText method there exists a parameter SpecificationName which says:
A string expression that's the name of an import or export specification you've created and saved in the current database. For a fixed-width text file, you must either specify an argument or use a schema.ini file, which must be stored in the same folder as the imported, linked, or exported text file.
To create a schema file, you can use the text import/export wizard to create the file. For delimited text files and Microsoft Word mail merge data files, you can leave this argument blank to select the default import/export specifications.
So if you are not able to generate that schema.ini file using the wizard you can generate it yourself in the same folder as your files to import. For a documentation how to build that file see Schema.ini File (Text File Driver).
It should look something like the following I think:
[YourImportFileName.csv]
Format=Delimited(;)
DecimalSymbol=","
Note that you have to generate one ini file for each CSV file you want to import because the first line is always the name of the import file. So generate the schema.ini, import, delete the ini and start over generating the next ini for the next file.
If you want to generate that ini file with VBA on the fly, have a look at How to create and write to a txt file using VBA.

Related

Howto handle umlauts in Logic App for export to csv

I created a logic app to export some data to a *.csv file.
Data which will be exported contains german umlauts.
I read all the needed values into variables which are then concatenated and added to an array.
Finally I get an array of semicolon separated strings with the values in it.
This result will then be added to an email as file attachment:
All the values are handled correctly in the Logic App and are correct in the *.csv file but as soon I open the csv with Excel, the umlauts are not shown correctly anymore.
Is there a way to create explicitly a file with the correct encoding within the logic app and add the file to the email instead of the ExportString?
Or can I somehow encode the content of the ExportString-Variable?
Any hints?
I have reproduced in my environment and followed below steps to get correct output in CSV file:
My input is:
I have sent the data into CSV table as below and then created a file in file share as below:
Then when i open my file share and download the content from there i got different output as you got:
Then I opened my Azure Storage explorer and downloaded it as below:
When i open in notepad the downloaded file:
I get the correct output, try to do in this way
And when i save it as hello.csv and keep utf-8 with bom like below:
Then I get the correct output in csv as well:

Read only specific csv files in azure dataflow source

I have a data flow source, a delimited text dataset that points to a folder containing many csv files.
So the source reads all the csv files inside the folder2. The files inside folder2 are
abc.csv
someFile.csv
otherFile_2021.csv
predicted_file_1.csv
predicted_file_2.csv
predicted_file_99.csv
The aim is to read data from only the files like predicted_file_*.csv i.e to only read the last three files. Is it possible to add dynamic content in dataset so that it reads specific pattern files?
In source transformation, under source options, you can provide the wildcard path with filename prefix to read the required files.
Example:
(For debug purpose, I have added column to store the filename to verify the files)
Source:
Source preview:
Refer this document for more information.

How to import data in csv format in J?

I want to know how can I import data in CSV and then how I can deal with it?
I had loaded the file but do not know how to read it.
'',' fixdsv dat ] load '/Users/apple/Downloads/data'
Assuming that the file /Users/apple/Downloads/data is a csv file then you should be able to load it into a J session as a boxed table like this:
load 'csv'
data=: readcsv '/Users/apple/Downloads/data'
If the file uses delimiters other than commas (e.g. Tabs) then you could use the tables/dsv addon.
data=: TAB readdsv '/Users/apple/Downloads/data'
See the J wiki for more information on the tables/csv and tables/dsv addons.
After loading the file, I think that I would start by reading the file into a variable then working with that.
data=: 1:!1 <'filepath/filename' NB. filename and path need to be boxed string
http://www.jsoftware.com/help/dictionary/dx001.htm
Also you could look at jd which is specifically a relational database system if you are more focussed on file management than data processing.
http://code.jsoftware.com/wiki/Jd/Index

CSV in UTF-8 and Microsoft Excel

In my application I have a list of items which can be exported to CSV.
For this, I create a Blob as follows:
var BOM = "\ufeff";
var blob = new Blob([csv], {
type: 'csv;charset=utf-8'
});
In case that the data in this list contains special characters, the exported file was not opened correctly in MS Excel. So I added a line to my code (the second line in the following snippet), as I found in many Q&A forums:
var BOM = "\ufeff";
var csv = BOM + csv;
var blob = new Blob([csv], {
type: 'csv;charset=utf-8'
});
That works - the CSV is opened correctly in Excel, but then, when saving the file - it is save in text format and not as CSV. Which meant I need to "Save As" the file and change the default type if I want it to be saved correctly.
Is it really like this? Do I really have to choose between the two options - see the file or save it correctly?
Yes this is a shame but it is really like this. From Excel a CSV is ANSI encoded per default and there is not a directly possibility to save CSV in any unicode encoding. Microsoft itself suggest using Notepad to change the encoding. See How to save an address book to a CSV file by using the UTF-8 encoding format so that the CSV file can be imported to Windows Mail. See also How can I save a csv with utf-8 encoding using Excel 2013?
Only other possibility is using VBA and create the CSV file using ADODB.Stream or Scripting.FileSystemObject.
How to use ADODB.Stream to create unicode encoded CSV file is answered multiple times already. For example: how to Export excel to csv file with "|" delimted and utf-8 code. Simply change the delimiter "|" to ",". This is the basic approach. Maybe you have to extend it to provide text delimiter also, if the delimiter can be part of the data.
Using CreateTextFile Method of Scripting.FileSystemObject is simpler but only allows Unicode which is UTF-16LE rather than UTF-8.

Bulk Insert or any other insert options to insert file contents without providing file path

I want to know if it is possible to import a file's contents without knowing the exact file location/path. Instead of the file path, the file contents will directly be passed in as a string, to say a stored procedure.
How can I utilize any of the insert options like BULK INSERT or OPENROWSET etc. to import/copy data directly from input as string (instead of giving file path), and please do give some examples or links, with code if possible.
If more details are needed, I can provide. Or, do I have to perform string manipulation with looping of some kind to input the huge string file blob into respective tables/columns?

Resources