Using Aspose.Cells in MS SQL Server – CLR

Here are the steps to take to use Aspose Cells in SQL Server:

1) Download Aspose.Cells from http://www.aspose.com/community/files/51/file-format-components/aspose.cells/default.aspx

2) Install Aspose.Cells — The current version is install in C:\Progra~1\Aspose\Aspose.Cells\Bin\Net2.0

3) Write C# Module function such as

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;

using Aspose.Cells;

public class EphAspose
{

   static String strFileNameXLS = @"C:\EphAspose1.xls";

   static void Main()
   {

     /*
     EphAspose objAspose = null;

    objAspose = new EphAspose();

    objAspose.tryAspose();

    objAspose = null;
   */

   tryAspose();

   }

   static public void tryAspose()
   {

      /*
         Object objApp = Path.GetDirectoryName(Application.ExecutablePath);

         string cellsLicenseFile = Path.Combine(objApp, "Aspose.Cells.lic");

         if (System.IO.File.Exists(cellsLicenseFile))
         {

            //This shows how to license Aspose.Cells.
            //If you don't specify a license, Aspose.Cells works in evaluation mode.
           Aspose.Cells.License license = new Aspose.Cells.License();
           license.SetLicense(cellsLicenseFile);
        }

    */

        //Instantiating a Workbook object
        Workbook workbook = new Workbook();

       //Adding a new worksheet to the Excel object
       workbook.Worksheets.Add();

       //Obtaining the reference of the newly added worksheet by passing its sheet index
       Worksheet worksheet = workbook.Worksheets[0];

       //Adding a string value to the cell
       worksheet.Cells["A1"].PutValue("Hello World");

       //Adding a double value to the cell
       worksheet.Cells["A2"].PutValue(20.5);

       //Adding an integer value to the cell
       worksheet.Cells["A3"].PutValue(15);

      //Adding a boolean value to the cell
      worksheet.Cells["A4"].PutValue(true);

      //Adding a date/time value to the cell
      worksheet.Cells["A5"].PutValue(DateTime.Now);

      //Setting the display format of the date
      worksheet.Cells["A5"].Style.Number=15;

      //Saving the Excel file
      workbook.Save(strFileNameXLS,FileFormatType.Default);

    }

}

4) Compile the source code

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe /target:library /debug+ EphAspose1.cs /r:C:\Progra~1\Aspose\Aspose.Cells\Bin\Net2.0\Aspose.Cells.dll

5) Deploy Aspose.Dll

  • Copy all of the framework dll from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 unto C:\Progra~1\Aspose\Aspose.Cells\Bin\Net2.0

 

6) Deploy User Assembly


CREATE ASSEMBLY EphAspose1
FROM 'C:\DanielAdeniji\SQLScripts\PGE\CLR\20080515\Lab2\EphAspose1.dll'
WITH PERMISSION_SET = UNSAFE
go

 

7) Create Stored Procedure and reference Assembly


CREATE PROC usp_EphAspose1
as EXTERNAL NAME
EphAspose1.[EphAspose].tryAspose;

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s