Import Txt file to access database - c#

i have a txt file with format
10000025|246|31032017|00|0|0.00|0.00|0.00|0.00|0|0.00|0.00|0.00|0.00|0.00|0.00|0.00|R
10000025|246|31032017|01|0|0.00|0.00|0.00|0.00|0|0.00|0.00|0.00|0.00|0.00|0.00|0.00|R
10000025|246|31032017|02|0|0.00|0.00|0.00|0.00|0|0.00|0.00|0.00|0.00|0.00|0.00|0.00|R
10000025|246|31032017|03|0|0.00|0.00|0.00|0.00|0|0.00|0.00|0.00|0.00|0.00|0.00|0.00|R
i want import to access database using C# code
If someone has a clue about how to perform something like this, i would be grateful !

I dont think there is any need to use c# sort of thing in this scenario. You can accomplish this task by using an excel sheet. Copy the whole txt file and paste it into the excel sheet, once done Select the header of the cell in which you copied the text (Lets say 'A'). Now in the top menu navigate to Data Tab and select "Text to Columns". A dialogue will appear where you can select Delimited (which is default selection) and click next there you will find the delimiters section where you can specify your delimiter like comma, semi colon, etc. In your case the separator is pipe character '|' so you can specify the pipe character in a text box given in the delimiter list.
Once done click next and finish you will get the data in a column and row form exactly what you were looking for now you can import the data to sql, access or to what ever you want take a look at this Link to know how to import data from excel to access
I am attaching following screen shots
Picture of text data being copied in excelwith header selected
Screen shot of delimiter screen where you will specify the pipe character

Related

How to not skip empty cell in Excel when creating .csv file

hope you guys can help!
I am trying to create .csv out of Excel which would have columns A - H filled with some data I want to read but data is optional. So some times the first column A can be empty. Now, when I save the .csv, unless I entered one space in the A column, Excel automatically trims A column, and the result is 7 cells to read A - G instead 8 cells A - H (with A column) being "empty". I would like to save client the trouble of needing to enter one space or -> ="" in the Excel formula to make first or last column "empty" but not trimmed in the resulting .csv.
Thank you!
There is no option in Excel to preserve empty columns, when exporting to .csv. But you could introduce a header text in the first row, so you will always have the columns filled atleast with the header text.
Plus it would make your data probably more readable, depending on what data this is.
Another possibility would be to implement a makro and embedd a button in your excel file:
see
how not to skip empty first cell when saving as .CSV?

creating multiple txt files and directories from csv column and have the txt files filled with specific text

I have an excel file containing MANY names column and many links column, i need to create directories and text files inside them based on the excel column *. text files filled with same text inside them
Lets say i have an excel file containing column:banana,apple
The output would be Banana directory,apple directory.
Inside apple directory apple.text,inside banana directory a file called banana.text.
Inside the text files banana.text and apple.text i would like to have the same specific text WITH the links as variable inside banana.txt the same text with the apropriate link to banana in the paralel link's column and for apple.text same specific text with the appropriate link to apple in the apple link's column pls .
lets saythe text inside apple.text will looks like:
hello and nice to meet u http://apple.com
lets saythe text inside banana.text will looks like:
hello and nice to meet u http://banana.com
same words in each file just the link will be changing.
I EDITED THE QUESTION.
I think there steps needs for you.
first, automated Exccel.
https://support.microsoft.com/en-us/help/302084/how-to-automate-microsoft-excel-from-microsoft-visual-c--net
find URLs.
There is many ways for that. I recommended using Regular Expression.
find Keyword.
in URL, remove http protocal related keywords.

Tab Delimited Text Copy Paste To Excel

I am generating a block of text via C# Stringbuilder, with appropriately tab-delimited text (new lines, "\t", etc.) and displaying the text within a tag in my web application. If I copy/paste this to Excel, all the text pastes into the first column on the spreadsheet.
If I copy the outerHTML of the block (Chrome) or copy/paste into Notepad++ and THEN paste to Excel, all the data pastes neatly into individual cells - which is the desired outcome of this effort. Can anyone tell me what I need to do in order to be able to copy the text from my application and paste it into Excel, so that the text pastes into individual cells (ie, keeps the tab-delimited format)?
Unfortunately, it appears an extra step is required.
The default behaviour of paste in Excel (& many other applications) is to use the original format of the contents of the clipboard.
Copying from a web application/HTML page will result in the clipboard contents being flagged as HTML. The clipboard contents will have the tab character, but as HTML renders tabs to whitespace (compacting to a single whitespace if there are multiple tabs) - just using control-V will convert the tabs to spaces & the contents will appear in a single cell when pasting into Excel..
You will need to use the "Paste Special" option & select "Unicode text" to retain the tabs. There is no way to set this by default : https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_windows8-mso_365hp/how-to-change-default-paste-behavior-with-ctrl-v/f58da075-8fd5-4c80-a64b-5e71ec8ad38b?auth=1
Copying the outerHTML of Chrome sets the clipboard format to text in the first place, pasting to Notepad++ does paste as text rather than HTML then recopying sets the format to text - which is why these methods work.
I was able to paste to Excel and keep the format by changing the element my text wrote to from a div to textarea. Copy/paste of tsv from textarea to a tab-delimited Excel spreadsheet keeps the data formatted in tabular format when pasted. Thanks all for the help.
Try this ,
Before pasting data set excel's text to column delimiters to space and try to paste your values again.
Old topic but I had this. Need to copy something each day from a programme which outputs to google chrome browser. Whenever it was copied and pasted into excel it was going into 1 cell. Yet if I control all and paste it was ok.
I found you can copy only the lines you want and it will behave as wanted - if you don't drag the cursor all the way down off the page. ie if you highlight down to the last piece of information in the bottom right of screen more carefully, when you past to excel it pastes it as tab separated. Whereas if you drag it right down it pastes it all in 1 cell. Might help someone in the future who has this.
You can use 'text to columns' in Excel to format the data in the way you want it to.
After pasting the data into excel, select the column with your data.
Go to Data - click 'Text to columns'
Choose delimited and hit next
Choose Tab and hit finish.
If you don't want to use this extra step, the following works for Excel 2013:
Go to Home, Paste options and click 'Use text import wizard'
Choose delimited and hit next
Choose Tab and hit finish.

Export To Text file with Text Align

how can i export set of data in SQL or Access to text file with text align ?
there is a AS400 system. witch employees have to enter Purchase orders one by one.
(customers send their Purchase orders by Excel)
i created a tool using C# to import excel and import to a access DB
and i want to know how to export to a text file with correct text length.(so i can import to the System Direcly)
this is the format i want
Name| Width|Type|Alignment|Remark
NO|10| N| Right left | pad with blank
Type|2| C| Left|Default 'SO'
Company|5| C| Left| Default Blank
Depot Code|12| C|Right| left pad with blank
Customer Code|9|N| Right|left pad with blank
Out put :--
40000013SO 211 5031JHX400B PKPK 500 041013
You can achieve this just using string.Format(). Take a read of http://msdn.microsoft.com/en-us/library/system.string.format.aspx. If is possible to specify the width of a field and its text alignment, thus allowing you to lay out the fields as per your requirements.

How to keep first 0 in csv when open it and save as in Excel

I created csv file in format "Surname;Birthday;Name". Where Birthday is in format ddmmyyyy (e.g. 01121989 or 09111983).
When I opened it in Excel It did not show first '0'.
Can I escape this symbol to show full date in Excel?
When I saved this file from Excel using option "Save as" It lost first '0' in Birthday. Is it possible to prevent this?
Thank you.
In stead of opening the csv as you normally would use a data connection.
For this go to your ribbon item Data > From Text
Browse to your CSV and select Open. Now you will get a text-to-columns window where you can set the specific column properties to Text (so not General or Number). This way the complete set of characters are available.
Once you open the file, right-click the column letter (e.g., B) and select Format Cells. Then choose Custom, and set the format to 00000000. This will add the leading 0 to all cells where it is missing, and when you save it as .csv, it will export the leading 0 in the output file too.
This is typical Excel. You can consider using single quotes:
A,'01121989',B
If you are using a program to read this file you can clear these single quotes easily.
Format your date cells as Text.
Right-click, Format Cells, under Category select Text.
Normally, when you enter some number in Excel, you will see it aligns right, if you enter the same numbers in a Text formatted cell, it will align left, and any zeroes at the starts will be kept.

Categories