Free Support Forum - aspose.com

Set column width having merged cells in the worksheet in .NET

I am having a problem setting som colum width to zero in the attached spreadsheet. I am trying to set colums R though Z to zero using the followinf code:

Dim i, j As Integer

For i = 0 To wb.Worksheets.Count - 1
For j = 1 To 30
wb.Worksheets(i).Cells.SetColumnWidth(j, 0)
Next
Next

What it seems to do is starting the column index after the merged columns That just doesnt seem right.

Thanks

Hi,


I tested your code with your template file with latest version/fix v6.0.0.6(attached), it works fine. I think it works same as MS Excel.

Please try it and let us know if it works fine.

Thank you.

Thanks. I tried that version and I get a ton of Error 4 'Style' is not a member of 'Aspose.Cells.Cell' errors.

I'm currently using version 4.8. Is there a version I can upgreade to that my issue will be resolved without having to redo all the Style applications?

Thanks agian.

Chris

Hi Chris,


Well, you may try some other versions (if possible for you and your license allows) e.g v4.9 etc.

And regarding using latest versions with their APIs, for
your complete reference, I think firstly you should check the release notes for
different official versions of Aspose.Cells for .NET (especially v5.0.0 and
5.1.0 etc.).<o:p></o:p>

http://www.aspose.com/community/files/51/.net-components/aspose.cells-for-.net/entry243604.aspx

http://www.aspose.com/community/files/51/.net-components/aspose.cells-for-.net/entry248967.aspx

Note: Check the description under "Notable Changes for Existing Users" for API changes.

For Workbook.Open and Workbook.Save methods warning messages, please see the documents for your reference:

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/opening-files.html

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/saving-files.html

Moreover, please check the documentation of the product for complete details:

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/programmers-guide.html

Let me come towards your significant errors that you may encounter, so you can fix them accordingly:

1) You need to import the relevant namesapaces to your demo pages or use fully qualified naming when declaring objects for classes etc.:

e.g

using System;

using System.Web;

using Aspose.Cells;

using Aspose.Cells.Pivot;

etc.

2) As I said above, some classes are renamed. e.g

i) Validations --> ValidationCollection

ii) PivotTable --> PivotTableCollection

etc.

3) Aspose.Cells.Style property is eliminated/obsoleted now, you should adjust your code to use Aspose.Cells.GetStyle() and Aspose.Cells.SetStyle() methods, it will also enhance the performance to certain extent:

e.g

Your sample code using Style attribute should be updated accordingly, e.g

Style style = wsNdaa.Cells[0, 0].GetStyle();

style.Font.IsBold = true;

wsNdaa.Cells[0, 0].SetStyle(style);

Styyle style2 = cells["I1"].GetStyle();

style2.HorizontalAlignment = TextAlignmentType.Center;

style2.BackgroundColor = System.Drawing.Color.Navy;

style2.Font.IsBold = true;

cells["I1"].SetStyle(style2);

For complete reference about Cell.GetStyle/SetStyle approach, please see the documents in the section:

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/working-with-data-formatting.html

4) Please check Aspose.Cells for .NET API Reference:

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/aspose.cells-for-.net-api-reference.html