I'm having a stored procedure that returns printed text. E.g
To import this report into Excel (and preserve leading zeros in numbers, etc):
Click here, then press CTRL-A, CTRL-C.
Open Excel, press CTRL-A, right-click mouse, select Format Cells, click Text.
Click on A1 cell, press SHIFT-INS to paste.
REPORT FOR 21-09-2013
Date Who Total
21-09-2013 ALBERT 10
So i want to be able to retrieve this text from my C# application. I've tried to retrieve it via ExecuteScalar() and ExecuteReader() but no luck. Is there any other alternative to solve this problem ?
Related
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.
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
Hello i develop software with c#, this software load value from sql server database, i have problem with money value read from sql server, for example: in sql server i have save price value with this value:
but when i load value from sql server and I go inside into datagridview the value It is read as:
how to take off the decimals in more?
You can Set you Format String using CellStyle Builder an set the Custom format to # mm
How to do it :
1 .Right click on Grid, then Properties
2. In the property window, click the button that will popup up the Edit Columns Dialog
3. Select the cell you want to format
4. On the right side of the Edit Columns Dialog select the DefaultCellStyle property Click the DefaultCellStyle property
5. CellStyleBuilder dialog will open Here you have the format property, this will give you the Format String Dialog
6. Set the Custom property to N2 you will see the preview at the bottom
7. Click OK . till you are back to your Grid.
If you want to do it from Code, put this code inside Form_load event.
yourgridnAME.Columns["Amount"].DefaultCellStyle.Format = "N2";
I just trying to change textbox text dynamically in Crystal Reports using a formula but I did not find where should I put the formula?
Shalini Khare
On crystal report , you can find FormulaFeild section. Right click that and add new formula and apply your logic
EDIT
Instead of textbox write a formula and place the formula in the textbox place.
Step 1-Insert textbox
Step 2- On crystal report ,Open Formula field section. Right click that and add new formula.
Step 3- Give name of Your formula and click OK
Step 4- Write down formula to change textbox text dynamically Like
If{Table.TotalMarks}>400 then "Pass"
Else "Fail"
Step 5- Save and Close
Step 6- Drag this formula from Formula Field and drop it into textbox
Step 7- Now execute your program
Step 1- Insert two Text box (At same place)
Step 2- Write Pass in first textbox and fail to another
Step 3- Right Click On First textbox
Step 4- Select format object
Step 5 Check On Suppress checkbox
Step 6 Open Suppress formula editor and put your formula like
if {Table.TotalMarks}> 400 then
true
else
false
Step 7 Save and close
Step 8-Apply same for second textbox (change formula)
Step 9 Now execute your program
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.