Change cells alignment with existing formatting intact and encrypt or decrypt ODS files using Aspose.Cells for .NET 18.7

Aspose.Cells for .NET logo
We are pleased to announce the release of Aspose.Cells for .NET v18.7. Please check the document on how to install Aspose for .NET APIs directly from NuGet repository. In this release, we have added some utility features for the users. Moreover, we included important fixes and other enhancements in the release. Please check the release notes in order to get an idea about what is new and what has been enhanced or fixed with this revision of Aspose.Cells for .NET.

Change Cells Alignment and Keep Existing Formatting

If you need to change the alignment of multiple cells but also want to keep existing formattings intact, Aspose.Cells allows you to do that using the StyleFlag.Alignments property. Please note, StyleFlag object is passed as a parameter to Range.ApplyStyle() method which actually applies the formatting to your desired range of cells. The following sample code loads the sample Excel file, creates the range and center aligns it horizontally and vertically and keeps the existing formatting intact.

// Load sample Excel file containing cells with formatting.
Workbook wb = new Workbook("sampleChangeCellsAlignmentAndKeepExistingFormatting.xlsx");
// Access first worksheet.
Worksheet ws = wb.Worksheets[0];
// Create cells range.
Range rng = ws.Cells.CreateRange("B2:D7");
// Create style object.
Style st = wb.CreateStyle();
// Set the horizontal and vertical alignment to center.
st.HorizontalAlignment = TextAlignmentType.Center;
st.VerticalAlignment = TextAlignmentType.Center;
// Create style flag object.
StyleFlag flag = new StyleFlag();
// Set style flag alignments true. It is most crucial statement.
// Because if it will be false, no changes will take place.
flag.Alignments = true;
// Apply style to range of cells.
rng.ApplyStyle(st, flag);
// Save the workbook in XLSX format.
wb.Save("outputChangeCellsAlignmentAndKeepExistingFormatting.xlsx", SaveFormat.Xlsx);

Please see the following article for more detail on this topic for your reference.

Find Maximum Rows and Columns supported by XLS and XLSX formats

For your information, there are different number of rows and columns supported by different MS Excel file formats. For example, XLS supports up to 65536 rows and 256 columns while XLSX supports 1048576 rows and 16384 columns. If you want to know how many rows and columns are supported by a given format, you can use Workbook.Settings.MaxRow and Workbook.Settings.MaxColumn properties. Please see the following article for more detail on this topic for your reference:

Specify Author while Write Protecting Workbook

You can specify author name while write protecting your workbook using Aspose.Cells API. Please use Workbook.Settings.WriteProtection.Author property for this purpose. Please see the following article for more detail on this topic for your reference:

Encrypt/decrypt an ODS file

Aspose.Cells allows you to encrypt and decrypt an ODS file. Decrypted ODS file can be opened both in MS Excel and OpenOffice, however encrypted ODS file can only be opened by OpenOffice after providing the password. Excel cannot open the encrypted ODS file and may raise warning message. For encrypting an ODS file, load the file and set the WorkbookSettings.Password value to the actual password before saving it. Please see the following article for more detail on this topic for your reference:

Other Enhancements and Fixes

There are some other enhancements included and a few exceptions handled in the new release for the users. A few of the worth mentioning features and other improvements are as follows.

  • Round images become square images in the output PDF.
  • Support Pivot Table Slicers.
  • Using “List<dynamic>” or “List<ExpandoObject>” as DataSource for importing data into worksheet.
  • Handled “Index out of range” exception in SheetRender.ToImage method.
  • Exception: “Invalid parameters for function iferror….” when loading an Excel file.
  • Invalid PatternType string value exception while loading a file.

In Aspose.Cells 18.7, we fixed several important bugs and other issues. For example, issues around reading/writing MS Excel file formats, applying data validation, manipulating OLE Objects, formatting ListObject/Tables, rendering and manipulating charts and shapes, manipulating PivotTables, rendering images from Excel worksheets, rendering images files from charts and exporting Excel workbooks to PDF format have been resolved in the release.

Changes to the Public API

The following is a list of any changes made to the public API such as added, renamed, removed or deprecated members as well as any non-backward compatible change made to Aspose.Cells for .NET:

  • Adds enum StyleFlag.Alignments, it represents all the settings of alignment.
  • Adds WorkbookSettings.MaxRow and WorkbookSettings.MaxColumn properties, these attributes gets the max row and column indexes of the workbook.
  • Adds WriteProtection.Author property, it gets and sets the author of the write protection.

Aspose.Cells for .NET Resources

The resources, you may need to accomplish your tasks: