Amjad Sahi February 2, 2016one Comment

Optimize PDF File Size, Re-size Chart’s Data Label Shape to Fit Text and Enhancements to Digital Signatures for VBA Projects with Aspose.Cells for .NET 8.7.0

Optimize PDF File Size, Re-size Chart’s Data Label Shape to Fit Text and Enhancements to Digital Signatures for VBA Projects with Aspose.Cells for .NET 8.7.0

February 2, 2016
Share on FacebookTweet about this on TwitterShare on LinkedIn

Aspose.Cells for .NET logoAspose.Cells for .NET 8.7.0 has been released. This release contains some useful features and other enhancements along with critical bug fixes. If you are planning to upgrade the Aspose.Cells for .NET API to the latest revision, we would strongly suggest you to check the complete Public API Changes section to know what has been changed in the API so far. We have highlighted some important features (of this month’s release) here.

While you are downloading the latest build, here is a look at the biggest features in this release.

Optimize PDF File Size

Aspose.Cells APIs have provided an enhancement for the PDF rendering engine in order to reduce the resultant PDF file size. Aspose.Cells for.NET 8.7.0 has exposed the PdfSaveOptions.OptimizationType property along with an enumeration by the name PdfOptimizationType in order to facilitate the application developers to control the resultant PDF file size to certain extent.

The PdfOptimizationType enumeration has 2 constants at the moment exhibiting the following behaviour.

  1. PdfOptimizationType.MinimumSize: API tries to optimize the cell text and cell border records in order to reduce the resultant PDF file size.
  2. PdfOptimizationType.Standard: No optimization is done therefore the resultant file size will be large as compared to PdfOptimizationType.MinimumSize selection.

The following piece of code demonstrates the usage of PdfSaveOptions.OptimizationType property to minimize the resultant PDF file size while exporting spreadsheets to PDF format.

string filePath = "Book1.xlsx";

//Load excel file into workbook object
Workbook workbook = new Workbook(filePath);

//Save into Pdf with Minimum size
PdfSaveOptions opts = new PdfSaveOptions();
opts.OptimizationType = PdfOptimizationType.MinimumSize;

workbook.Save("output.pdf", opts);

Re-size Chart’s Data Label Shape to Fit Text

Aspose.Cells for .NET 8.7.0 has exposed the Boolean type DataLabels.IsResizeShapeToFitText property in order to mimic the Excel’s feature of re-sizing data label shapes to fit the text.

Please note, Excel application provides the Resize shape to fit text option for chart’s data labels to increase the size of the shape so that the text fits inside of it. This option can be accessed on Excel interface by selecting any of the data labels on the chart. Right click and select Format DataLabels menu. On Size & Properties tab, expand Alignment node to reveal the related properties including the Resize shape to fix text option as highlighted below.

The following piece of code shows the simple usage scenario of DataLabels.IsResizeShapeToFitText property to re-size the chart’s data label shapes to fit text.

//Create an instance of Workbook containing the Chart
var book = new Workbook(inFilePath);

//Access the Worksheet that contains the Chart
var sheet = book.Worksheets[0];

foreach (Chart chart in sheet.Charts)
{
    for (int index = 0; index < chart.NSeries.Count; index++)
    {
        //Access the DataLabels of indexed NSeries
        var labels = chart.NSeries[index].DataLabels;

        //Set ResizeShapeToFitText property to true
        labels.IsResizeShapeToFitText = true;
    }

    //Calculate Chart
    chart.Calculate();
}

//Save the result
book.Save(outFilePath);

Here is a snapshot showing a simple bar chart before & after executing the above code.

Enhancements to Protection Module

Aspose.Cells APIs have enhanced the Protection class by introducing some useful properties & methods. Two of the most worth mentioning enhancements are as follow.

Detect if Worksheet is Password Protected

It is possible to protect the workbooks and worksheets separately. For instance, a spreadsheet may contain one or more worksheets that are password protected, however, the spreadsheet itself may or may not be protected. Aspose.Cells API for Java has provided the Protection.IsProtectedWithPassword field to detect if a worksheet is password protected. Boolean type Protection.IsProtectedWithPassword field returns true if Worksheet is password protected and false if not.

Verify Password Used to Protect the Worksheet

Aspose.Cells for .NET 8.7.0 has exposed the Protection.VerifyPassword method which allows to specify a password as an instance of String and verifies if same password has been used to protect the worksheet. The Protection.VerifyPassword method returns true if the specified password matches with the password used to protect the given Worksheet, false if specified password does not match.

Following piece of code uses the Protection.VerifyPassword method in conjunction with Protection.IsProtectedWithPassword field to detect the password protection and verifies the password.

//Create an instance of Workbook and load a spreadsheet
var book = new Workbook(inFilePath);

//Access the protected Worksheet
var sheet = book.Worksheets[0];

//Check if Worksheet is password protected
if (sheet.Protection.IsProtectedWithPassword)
{
    //Verify the password used to protect the Worksheet
    if (sheet.Protection.VerifyPassword("password"))
    {
        Console.WriteLine("Specified password has matched");
    }
    else
    {
        Console.WriteLine("Specified password has not matched");
    }
}

Load or Import Delimited File Containing Formulas

Aspose.Cells for .NET has provided support to identify & parse the formulas while loading CSV/TXT files having delimited plain data. Newly exposed TxtLoadOptions.HasFormula property when set to true directs the API to parse the formulas from the input delimited file and set them to relevant cells without requiring any additional processing.

The following piece of code demonstrates the usage of TxtLoadOptions.HasFormula property to load and import the CSV with formulas in it.

string csvFile = @"D:\Downloads\sample.csv";

TxtLoadOptions opts = new TxtLoadOptions();
opts.Separator = ',';
opts.HasFormula = true;

//Load your CSV file with formulas in a Workbook object
Workbook workbook = new Workbook(csvFile, opts);

//You can also import your CSV file like this
//The code below is importing CSV file starting from cell D4
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells.ImportCSV(csvFile, opts, 3, 3);

//Save your workbook in Xlsx format
workbook.Save("output.xlsx");

Create 2-Color Scale Conditional Format

This release of the API has has exposed the ColorScale.Is3ColorScale property that can be used to create 2-Color Scale conditional format. The said property is of type boolean with default value of true which means that the conditional format will be of 3-Color Scale by default. However, switching the ColorScale.Is3ColorScale property to false will generate a 2-Color Scale conditional format.

Please see the detailed article on Adding 2 & 3-Color Scale Conditional Formatting.

Other Enhancements & Fixes

The most notable enhancements in this release are as follow:

We have handled a few exceptions regarding reading/writing Excel files and rendering PivotTables and HTML file format.

In this release, several important issues have been addressed. For example, issues around manipulating Microsoft Excel file formats, manipulating Pivot Tables, applying styles, conditional formatting, rendering images from Excel worksheets, manipulating charts, rendering images files from charts and exporting Excel workbooks to PDF format have been resolved. We have further enhanced the Aspose.Cells formula calculation engine and fixed a few issues in this regard.

Moreover, in the new release, we have also fixed a few issues in the web based grid control provided by Aspose.Cells for .NET.

To see a complete list of enhancements and fixes, and to download Aspose.Cells for .NET 8.7.0, please visit the download page.

Join the Conversation

1 Comment

Leave a comment

Posted inAspose.Cells Product Family
 

Related Articles