LinqToCsv Set Column Width - c#

I am using LinqToCsv to export data from a database to a csv file. One of the columns is a DateTime object. Upon export, the DateTime column shows up as "#######" until I manually expand the column width to fit the entire DateTime output. Is there a way to manually set column widths so that I don't have to manually expand the row every time?

A csv file has no concept of column widths. You could possibly export an .xlsx file instead using a library such as EPPlus

CSV has no format attached. It is a plain text file comma/semicolon separated. You see the file that way because Excel is showing "empty" style for it. If you open the file with a notepad you´ll see the data correctly.
If you need any style you´ll have to migrate to a XLSX or XLS file.

Related

Open XML generate excel file : cell format as Text

I am trying to set the exported file format as Text.
Currently even if It set the cell values to string it shows as general in the exported file.
I tried to set
style index 0 still didn't help.
I want to set the cells as text instead of general.
Code used from here : https://learn.microsoft.com/en-us/office/open-xml/how-to-create-a-spreadsheet-document-by-providing-a-file-name

How to save OLEObject pdf file from excel

I have an excel file and one cell of every row contain embed pdf file object and remaining cells contain string values. Excel file looks like click here
I want to save this excel file data in sql database table, I can read the cell data of Date, Store, Category, Cost, Total, Method columns using oledb provider or using Workbook and Worksheet classes and save it in database table fine.
but coming to the Receipt column it showing null value when reading from either oledb or worksheet,
I want to save embedded object in local folder row wise and get filepath
Insert excel row data and for 'Receipt' column I need to save filepath
I will show this data in grid, for Receipt column I will set hyperlink and give filepath, so user can view the pdf that saved of that row.
How to implement using "Microsoft.Office.Interop.Excel" namespace and "OLEObject" class.
Any ideas please share it will helpful, I dont want to use third pary assembly references like GemBox, Aspose, etc.
Thanks,
Ajay

Reading formula calculated value from excel cell in c#

I am using linqtoexcel for reading from a excel sheet. the problem i face is that i can't read the formula calculated value from a cell, instead i get the actual value of the cell. Is there any way to read the end value of the cell from the excel sheet using linqtoexcel or by some other means.
linqtoexcel uses OleDB to access the sheet's data, and since OleDB does not allow the formulas to be accessed, you can't read the formula from the excel cell. You can only view the value for the cell.

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.

How to get the value of a merged cell?

I am working on a project which has to make pdf report from couple of Excel files. The files should look like this: http://img194.imageshack.us/i/24766860.jpg/ and the pdf should look like this: http://img96.imageshack.us/i/u2ntitled.jpg/ where the location column must have the value of the merged cell in the excel file(B2:E2).
So the difficulty is how to read the merged cell and put its value in the location column.
If that info is not enough I can add the source code. If you want any other info ask I'll give it right away.
Merged cells in excel are read by their first cell address. You should be able to pick up merged cell B2:E2 as B2

Categories