This project is read-only.


Please make sure you have completed the steps mentioned on How to extend Spring.Northwind to generate different Northwind reports?

Customer Labels using Aspose.Cells

Please follow the following steps to add Customer Labels report using Aspose.Cells

    1. Add sample "Northwind.xls" file in "Spring.Northwind.Web\App_Data\xls" folder. You can find this file in Download package/Source code of this project.
    2. Open "Web.xml" file on the root of "Spring.Northwind.Web" and add the following lines inside objects node
        <object type="Cells/CustomerLabels.aspx">
          <property name="CustomerDao" ref="CustomerDao" />
    3. Add a new folder named "Cells" in Spring.Northwind.Web.2010
    4. Add a new ASP.NET page named "CustomerLabels.aspx" in Spring.Northwind.Web.2010\Cells folder.
    5. Add a link to this "CustomerLabels.aspx" on "Default.aspx" so that you can access it when run the project in browser.
    6. Replace the html with
      <%@ Page Title="" Language="C#" MasterPageFile="~/Shared/MasterPage.master" AutoEventWireup="true" CodeBehind="CustomerLabels.aspx.cs" Inherits="Spring.Northwind.Web.Cells.CustomerLabels" %>
      <asp:Content ID="Content1" ContentPlaceHolderID="content" runat="server">
          <h2>Create Customer Labels report using Aspose.Cells for .NET</h2>
          <div class="componentDescriptionTxt">
              This demo illustrates how to create a well formatted Customer Labels report by using <a href="">Aspose.Cells for .NET.</a>
              <ul class="noPaddingUl">
                  <li>Aspose.Cells component gives you the agility to report your data in a variety of ways.</li>
                  <li>Aspose.Cells component is fully functional for creating all types of reports.</li>
                  <li>You may customize the size and appearance of everything on a report. </li>
                  <li>You can display the information the way you want to see it.</li>
              The demo generates a printed report
              <ul class="noPaddingUl">
                  <li>It has a two-page report header and uses photos for each category. </li>
                  <li>Spring.NET NHibernate is used to retrieve the data from the Customers table of Northwind database, to generate the report </li>
                  <li>You can either open the resultant excel file into MS Excel or save directly to your disk to check the results.</li>
              Click Process to see how example Prints customers' company names and addresses on 3-up labels. 
          <br />
          <asp:Button ID="btnProcess" runat="server" Text="Process" OnClick="btnProcess_Click" />
    7. Replace the code-behind with
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using Aspose.Cells;
      using System.Data;
      using Spring.Northwind.Dao;
      using Spring.Northwind.Domain;
      namespace Spring.Northwind.Web.Cells
          public partial class CustomerLabels : System.Web.UI.Page
              private ICustomerDao customerDao;
              public ICustomerDao CustomerDao
                  set { this.customerDao = value; }
              protected void Page_Load(object sender, EventArgs e)
              protected void btnProcess_Click(object sender, EventArgs e)
                  //Create a workbook based on the custom method of a class
                  Workbook workbook = CreateCustomerLabels();
                  workbook.Save(HttpContext.Current.Response, "CustomerLabels.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
                  //end response to avoid unneeded html
              public Workbook CreateCustomerLabels()
                  IList customersList = customerDao.GetAll();
                  //Open a template file
                  string designerFile = MapPath("~/App_Data/xls/Northwind.xls");
                  Workbook workbook = new Workbook(designerFile);
                  //Get a worksheet
                  Worksheet sheet = workbook.Worksheets["Sheet4"];
                  //Name the worksheet
                  sheet.Name = "Customer Labels";
                  //Get the cells collection in the worksheet
                  Aspose.Cells.Cells cells = sheet.Cells;
                  int row = 0;
                  byte column = 0;
                  for (int i = 0; i < customersList.Count; i++)
                      int remainder = i % 3;
                      Cell cell;
                      switch (remainder)
                          case 0:
                              column = 0;
                          case 1:
                              column = 3;
                          case 2:
                              column = 6;
                      //Get a cell
                      cell = cells[row, column];
                      //Put a value into it
                      //Get another cell
                      cell = cells[row + 1, column];
                      //Put a value into it
                      //Get another cell
                      cell = cells[row + 2, column];
                      string contact = "";
                      contact += (string)customersList[i].City + " ";
                      contact += (string)customersList[i].Region + " ";
                      contact += (string)customersList[i].PostalCode;
                      //Put the value to it
                      //Get another cell
                      cell = cells[row + 3, column];
                      //Put a value to it
                      if (remainder == 2)
                          row += 5;
                  //Remove unnecessary worksheets in the workbook
                  for (int i = 0; i < workbook.Worksheets.Count; i++)
                      sheet = workbook.Worksheets[i];
                      if (sheet.Name != "Customer Labels")
                  //Get the generated workbook
                  return workbook;
    8. Run the project using F5 and open CustomerLabels.aspx page. Click 'Process' button to generate the report.

Last edited Feb 28, 2014 at 2:41 PM by asposemarketplace, version 6