How to save OLEObject pdf file from excel - c#

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

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?

How to save pdf with TextBoxes in ASP.NET

I want to save my gridview in pdf.
The point is that all the cells, except the header row (columns title) and the first column (rows title), have to be PDF textboxes, so once I open the file I can write text inside.
How can I do it?
I have found that it is possibe to create a pdf with textfields but I have not found a way to make them in a specific part of the sheet.
I have tried to do so: Link 1

LinqToCsv Set Column Width

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.

Refresh PivotTable EPPlus

I am editing an existing spreadsheet in C# using EPPlus. I am altering the raw data on the second worksheet which is being used as the data source for a Pivot table on the first worksheet. My edits all work perfectly, the problem I am having is that when I load the spreadsheet output I have to manually update the Pivot table by clicking the Refresh Data button on the Excel toolbar.
Is there anyway to do this with C# EPPlus?
I've tried:
package.Workbook.FullCalcOnLoad = true;
and
package.Workbook.Calculate();
without success.
UPDATE
I couldn't find a mechanism for doing this in EPPlus so would still like to know if there is an answer. However, because I am editing a pre-existing Excel file, I was able to edit the properties of the existing pivot table in Excel and change the setting to automatically update on first load.
I couldn't find a way to achieve this using EPPlus.
However, you can enable the "Refresh the data when opening the file" property on the PivotTable manually before modifying the file, so that when you open the file using Excel, the content of the PivotTable will be calculated based on the modified data. You can find this property under the Data tab in the PivotTable options.
A bit late I know, but thought I'd post in case anybody else is looking for the same solution. You can do this in EPPlus by directly amending the XML for the pivot tables cache definition.
pivotTable.CacheDefinition.CacheDefinitionXml.DocumentElement?.SetAttribute(
"refreshOnLoad", 1.ToString());
Using EPPlus version 4.5.3.3.
Pivot tables have it's own calc context in Excel file. You manipulate calculation of formulas with FullCalcOnLoad property and Calculate() method
I bet this code from here will help you.
foreach (Worksheet sheet in package.Workbook.Sheets)
{
foreach (PivotTable pivotTable in sheet.PivotTables())
{
pivotTable.PivotCache().Refresh(); //could be some other method, but i hope you find right one
}
}
Add this to ExcelPivotCacheDefinition.cs
public bool RefreshOnLoad
{
get
{
return GetXmlNodeString("#refreshOnLoad") == "1";
}
set
{
SetXmlNodeString("#refreshOnLoad", value?"1":"0");
}
}
Go to Pivot Table options and check 'Refresh data when opening the file': https://www.extendoffice.com/documents/excel/1859-excel-refresh-pivot-table-on-open.html.
(Optional) If desired, users can disable 'Protected View' inside of their Excel installation: http://www.corporatefocus.com/support/how-to-disable-protected-view-in-microsoft-excel#:~:text=In%20Excel%20go%20to%20File,Enable%20All%20Macros%20by%20default.

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