I am using C# with EPPlus library.
The task is that I am opening an excel file, removing some sheets from it and saving it as a separate excel file.
The issue I am facing is that the excel sheet tabs at the bottom are moved out of view in the output file saved:
The activesheet is sheet 1, but the Sheet 1 tab is not visible on the excel file.
Is there any command using EPPlus which can amend this to look like:
Files saved by Excel can contain information about the width of the tab area. I am quite sure that EPPlus does not take care of this detail.
If you rename a .xlsx file to .zip and take the xl\workbook.xml file of it you will find a section that may contain an attribute 'tabRatio'. The attribute is present only if the width is adjusted manually. This attribute or the whole section may be deleted.
I did a test: I saved a file with too little space for the tabs and after deletion of the section the tab area looked fine again.
Maybe EPPlus generates the 'tabRatio' attribute but with useless values? Please check for it. If so, you might want to file a request for the developers to leave it out if it does not make sense.
Related
I have built a template engine for Excel at work. It has For...Each loops for populating columns and rows with the contents of passed template variables. A sheet can grow... like a couple of rectangles continents pushing each other to get enough space - leaving holes sometimes.
I have a source document (template) and a target document (output file). I am using EPPlus for copying cells from template to output file. This generic Excel engine is much slower than the handwritten Interop code (factor 2!!!).
A profiler showed me that the big time consumer is the Range.Copy(destinationRange) method. Soooo... actually I only want the destination cells to look the same as the source cells.
Is there a faster way?
Unzipping the Excel file, I see there is only one style file. The output file could start with the styles of the template file. But how can this be done? And how do I address style information?
(I will spent a look at the EPPlus source...)
I am using SpreadsheetGear 2012 in my application to load, modify then save a new copy of a template workbook.
My code takes invoicing information from a database and formats it for the workbook. Then the user will print an invoice from the formatted information using a button on the workbook.
I use a template workbook with some formatting already provided to make my life easier. Included on the original template workbook is a button that runs a VBA macro in the spreadsheet. The VBA macro loads successfully but the button just disappears in the new workbook.
Some of the steps I have tried to rectify the issue: I've added a new button, changed the VBA macro code from a function to a sub, saved the template file as a macro-enabled spreadsheet (.xlsm) and saved the revised copy as a macro-enabled spreadsheet file.
Has anyone experienced this issue and do you have a solution?
If you are using the Open XML file formats (XLSX/XLSM), then this is a known limitation:
http://www.spreadsheetgear.com/support/help/spreadsheetgear.net.7.0/#SpreadsheetGear_2012_Limitations.html
In short, SpreadsheetGear 2012 does not support reading/writing Form Controls (like buttons), as well as Cell Comments, when working with the Open XML file formats. So your button is getting dropped when the file is initially read into SpreadsheetGear.
If you want to preserve these objects through SpreadsheetGear, you will need to use the XLS (FileFormat.Excel8) file format, which does support them.
Issue:. Corrupt named ranges can to accumulate in the workbook XML and slow the workbook down, and cause error messages when worksheets are copied between workbooks. A workbook can only contain one range with a given name, so if two worksheets containing identical range names come together, it will produce an error.
Once way named ranges can become useless/corrupted is en the cells to which they refer are deleted They can be identified from the #REF error which appears:
My goal is to remove any #REF in the xml file within my excel file. I plan on using DocumentFormats.OpenXML. Currently I'm making a copy of my old excel file I then want to be able to access the XML within the new copy of the excel file.
System.IO.File.Copy(txbBrowse.Text, Path.Combine(Path.GetDirectoryName(txbBrowse.Text), Path.GetFileNameWithoutExtension(txbBrowse.Text) + "Repair" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + Path.GetExtension(txbBrowse.Text)));
I'm currently using WinFroms in C#
I can't seem to find any links on how I would achieve my goal. Any ideas on how I would go about opening and editing my XML file to remove all the #REF in my new copy of the excel file? If someone could give me some advice on this matter or refer me to a few links I would appreciate it.
I have been looking for a solution all over the last days and I found that this library EPPlus allows retrieving in the same time formatting besides the actual data, plus charts, if needed, from Excel files which is what I am aiming at the moment.
Could you please explain to me step by step how to read a Range of cells from an Excel (like A1:P34) file that resides at a certain path, via ASP.NET/C#?
PATH would be something like //ServerName/Folder1/Folder2/Folder3/ExcelFileName.xlsx
I looked over the web, but there is not explicit documentation for my level of C# expertise on this. I tried several examples but none displayed the Excel Range into the webpage. (e.g this one.)
Note: the three examples I have tried all included an File Upload Control, I do not need such. I want to read the Excel file from a specified location over the local network.
EPPlus library is available here.
If you can recommend me any simpler resources to understand EPPlus on:
-reading from Excel
-writing from Excel
-reading charts from Excel
This EPPlus does seem wonderful in its functionality.
To read a file off the server take a look at this:
Open ExcelPackage Object with Excel application without saving it on local file path
Just need to set the var path part for your file.
To actually put the excel data on a web page, that is not so easy. See this:
Generating a HTML table from an Excel file using EPPlus?
Response to Comment:
Hosting an actual excel sheet in web page is temperamental at best but there are ways to do it (I haven't tried it personally). SharePoint is probably your best option if you have it available. If not, you would have to use an iFrame or some kind of office web component. Check this out:
how to display excel sheet in html page
I am using HttpContext to export a data table to a CSV file which will be used in excel for people to look at. This very same file will later be imported and parsed to get values inserted and such. However there are some columns that need to be hidden in the final excel export but still need to be recognized when importing the file. So essentially when looking at the file through excel, people should not see the hidden columns, but they should be there and readable when parsing the file back. Is there a property that I need to set to make this happen?
This is not possible with the .CSV file format. It does not support flagging columns as invisible and excel will not, by default, hide any columns when you open a .csv file with it.
You would need a custom excel template/plugin and custom logic to detect and hide certain columns.
My recomendation is that you do not go this way. Choose a different export / edit strategy. If excel is a must, switch to exporting full excel documents where you can then customize the columns and define how and when they can be edited.