DNK Gif

Dot Net Knowledge

Labels

Showing posts with label Aspose. Show all posts
Showing posts with label Aspose. Show all posts

Tuesday, 7 July 2015

Opening password protected Excel2013 file using Aspose.cells

How to open Password protected Excel file ?

Hey! I am not going to hack or any thing like that, Of course password is needed to open the file. 

For this latest version of Aspose.cells.dll is needed.
This version  Aspose.Cells for .NET v8.5.0.2 supports this feature, you can download the same.

This is the code to do this programmatically.

            LoadOptions loadoptions = new LoadOptions( );            
            loadoptions.Password = "umesh1";    
            string filepath="C:\\Dev\\MyExcel.xlsx";       
            Workbook workbook = new Workbook(filePath, loadoptions);

Use Excel Sheet as DataBase

How to use Excel sheet as DataBase?

Excel sheet can be used as DataBase. Here it goes.
Latest version of Aspose.cells needed.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Cells;

namespace BirthDay
{
    public class Decider
    {
        public static string GetRecord()
        {
            string nameList = string.Empty;
            int startColumnDOB = 2;
            int startRowDOB = 1;
            int countExit = 0;
            string filePath = System.AppDomain.CurrentDomain.BaseDirectory;
            string fileName = System.Configuration.ConfigurationSettings.AppSettings["ExcelFileName"];          
            filePath = filePath + fileName;
            Workbook wb = new Workbook(filePath);
            Worksheet ws = wb.Worksheets[0];
            Cells cells = ws.Cells;
            IList<Person> personList = new List<Person>();
            int r = startRowDOB;
            int c = startColumnDOB;
            while (countExit < 5)
            {
                string cellValue = cells[r, c].StringValue;
                if (string.IsNullOrWhiteSpace(cellValue))
                {
                    countExit++;
                    continue;
                }
                string[] dob = cellValue.Split('/');
                int month = 0; 
                int.TryParse(dob[0], out month);
                int day=0;
                int.TryParse(dob[1], out day);
                DateTime dateToday = DateTime.Now.Date;
                if ((month == dateToday.Month) && (day == dateToday.Day))
                {
                    Person person = new Person();
                    person.Id = decimal.Parse(string.IsNullOrWhiteSpace(cells[r, c - 2].StringValue) ? "0" : cells[r, c - 2].StringValue);
                    person.Name = cells[r, c - 1].StringValue;
                    person.DOB = dateToday;
                    nameList += person.Name + Environment.NewLine;
                }
                r++;
            }
            return nameList;
        }
    }
}

For security purpose password protected ExcelSheet can be used.
Download the Sample Project here.

Thursday, 25 June 2015

Wednesday, 3 June 2015

Initialize License file of Aspose

How to Initialize License file of Aspose?

License initialization can be done in the Global.asax file or you can put the code in the constructor of your class, which you are using for the generation of your excel report.

Codes:
 Here my class name is ReportBuilder. I have put the Aspose.lic file in a folder "License" in my project. I have written the path in a .cs file name AppConstant to avoid hard coding in project and i am using it here.

Note:
Write the path in the AppConstant file like this
public const string ASPOSE_LICENSE_PATH = ".License.Aspose.Total.lic";


public ReportBuilder()
  {            
     string fileKey = string.Concat(this.GetType().Namespace, AppConstant.ASPOSE_LICENSE_PATH);
            Stream file = Assembly.GetExecutingAssembly().GetManifestResourceStream(fileKey);
            Aspose.Cells.License cellsLicense = new Aspose.Cells.License();
            cellsLicense.SetLicense(file);
        }

First i am assigning the path to a string variable filekey. Now i am getting the Project directory of the server by the code this.GetType().Namespace and by concatenation i am getting the full path of the license file. Then i am converting the file to MemoryStream object and setting the license. SetLicense() method supports other over loads also. For my convenience i have used like that.

Another important thing here is set the BuildAction of the "Aspose.license" file to "Embedded Resource" instead of "None"

How to do this?
Right click on the Aspose.license file , go to property, now set the BuildAction to Embedded Resource.

So setting license file for Aspose is done.

Tuesday, 2 June 2015

Generate Excel Report dynamically using Aspose.cells and Dot Net Overview

Aspose.Cells for .NET



Aspose.Cells for .NET is an Excel spreadsheet programming component and library that allows software developers to manipulate and convert spreadsheet files from within their own applications. A combination of APIs and GUI controls, Aspose.Cells for .NET speeds up Microsoft Excel programming and conversion.

The APIs give developers powerful tools for performing simple file conversions or more complex tasks. Developers have control over page layout, formatting, charts and formulas. They can read and write spreadsheet files and save out to a variety of image, portable and text file formats.

Aspose.Cells for .NET is fast and reliable. It saves time and effort compared to developing your own spreadsheet manipulation solution or using Microsoft Automation.