epplus

Password Protected Excel Download using EPPLUS

不羁的心 提交于 2019-11-29 21:06:40
问题 I am exporting data in Excel form using EPPLUS Excel Library. I want that when excel downloaded it will ask for password. I have tried following code. FileInfo newFile = new FileInfo("sample.xlsx"); using (ExcelPackage package = new ExcelPackage(newFile) { ExcelWorksheet ws = package.Workbook.Worksheets.Add("demo"); ws.Cells[A1].LoadFromDataTable(dataTable, false); package.Workbook.Protection.SetPassword("EPPLUS"); package.Save(); } 回答1: Just need to use the .Save overload with a password as

Create advanced filter

冷暖自知 提交于 2019-11-29 17:14:16
I am trying to create an advanced filter in Excel from C# to copy unique data from one sheet to another, at least I get it in Excel and if I use Interop like this : Excel.Range rang = sheet2.get_Range("A2"); Excel.Range oRng = sheet.get_Range("I2", "I" + (lst.Count + 1)); oRng.AdvancedFilter(Excel.XlFilterAction.xlFilterCopy, CriteriaRange: Type.Missing, CopyToRange: rang, Unique: true); Works fine but I'm doing all my application with EPPlus and it will be better if I can do the same without Interop. So, it is possible? Since Advanced Filter is an excel function you need the full Excel DOM to

Use epplus to create .xlsm file

隐身守侯 提交于 2019-11-29 17:04:25
I'm trying to have a website export a .xlsm file and I can't seem to find anything that helps. Here's a simple example I'm using to test building a .xlsx file (which works). @using OfficeOpenXml; <html> <body> <div id="page-wrapper"> @{ // Change file extension to xlsm to test string fileExtension = "xlsm"; ExcelPackage p = new ExcelPackage(); p.Workbook.Worksheets.Add("Worksheet Name"); int LatestWorksheetNumber = p.Workbook.Worksheets.Count; ExcelWorksheet ws = p.Workbook.Worksheets[LatestWorksheetNumber]; ws.Cells[1, 1].Value = "Test"; //Generate A File Byte[] bin = p.GetAsByteArray();

EPPlus ColumnStacked chart data point colors

余生颓废 提交于 2019-11-29 16:38:00
I am able to generate Column Stacked chart using EPPlus. There is is requirement to change the color of datapoint. I found the solution of at enter link description here but it only changes the color of first datapoint of the series. Can I get help to change the color of other datapoints as well. Here is the concept that I am looking for enter image description here Here is the function that helps to change datapoint first color public void SetDataPointStyle(OfficeOpenXml.Drawing.Chart.ExcelChart chart, ExcelChartSerie series, int totalDataPoint, Color color) { var i = 0; var found = false;

Microsoft.Office.Interop.Excel or EPPlus for read a huge (or not) Excel file

北城余情 提交于 2019-11-29 16:12:45
I wrote a code to read a column from a Excel file. I use Microsoft.Office.Interop.Excel on this, first read the entire Range and then write in System.Array after that I do some operations with the System.Array values and finally I convert it to List because I fill a ListBox element. This is the code (only relevant parts): private List<string> bd = new List<string>(); private static System.Array objRowAValues; private List<string> bl = new List<string>(); private static System.Array objRowBValues; private List<string> cm = new List<string>(); private static System.Array objRowCValues; private

EPPLUS how to know the format of the Worksheet cell

孤者浪人 提交于 2019-11-29 14:52:40
I am using EPPlus to read excel sheets and load the data into datatable to perform further operations and then save back the modified data to the excel file. The below code checks if the cell value is a float value then it converts the float value to datetime. The code works fine when the cell value is a date eg: Invoice Date = 42009 , but it converts the not a date value like eg : amount = 10 to a date. Is there any way in EPPlus library from which i can determine the format of the cell (i.e General/date/number etc) ? float floatValue; if (float.TryParse(Convert.ToString(oSheet.Cells[i, j]

Unit testing classes that use EPPlus

喜欢而已 提交于 2019-11-29 11:09:13
I am having issues unit testing classes that use EPPlus. In my mind, I have two options. I can mock & inject the HttpPostedFileBase into a method, or I can mock & inject the EPPlus ExcelPackage class. Mocking the HttpPostedFileBase, at least doing a true mock, seems limited. I can mock the basic properties on the file (MIME type, filename, etc), but to mock its InputStream in a way that allows the tests to actually interact with it, seems extremely difficult. The only solution I can come up with is to provide a real excel file, create a real FileStream with it, and assign that FileStream to my

Merge cells using EPPlus?

£可爱£侵袭症+ 提交于 2019-11-29 10:30:56
问题 I'm using the EPPlus library to read/write Excel files: http://epplus.codeplex.com/ I'm trying to simply merge some cells when writing a document: using (ExcelPackage pck = new ExcelPackage()) { //Create the worksheet ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo"); //Format the header for column 1-3 using (ExcelRange rng = ws.Cells["A1:C1"]) { bool merge = rng.Merge; } } There's a property named Merge that simply returns true or false. I thought maybe that would Merge the cells, but

Get Merged Cell Area with EPPLus

寵の児 提交于 2019-11-29 10:27:28
I'm using EPPlus to read excel files. I have a single cell that is part of merged cells. How do I get the merged range that this cell is part of? For example: Assume Range ("A1:C1") has been merged. Given Range "B1" it's Merge property will be true but there isn't a way to get the merged range given a single cell. How do you get the merged range? I was hoping for a .MergedRange which would return Range("A1:C1") There is no such property out of the box but the worksheet has a MergedCells property with an array of all the merged cell addresses in the worksheet and a GetMergeCellId() method which

Autofit Row Height of Merged Cell in EPPlus

ぐ巨炮叔叔 提交于 2019-11-29 10:23:08
I'm using EPPlus and C# and trying to autosize/autofit the height of a row to accommodate the height needed to show all of the contents of a merged cell with text wrapping. However no matter what I try the text always truncates. Since I'm repeating this process with various text sizes on various worksheets, I don't want to hard code the row height (except to enforce a minimum height for the row). If possible I'd like to do this within EPPlus/C#. With the cells A2:E2 merged and WrapText = true: Cell with Text Truncated Here's what it should look like with desired Cell Height Here's my relevant