Free Support Forum - aspose.com

Why unnecessary border top on a cell when the cell above it has border bottom in .NET

Hello.
I'm working on Aspose Cells and I notice a bug or unwanted feature.
I attached an excel file, a screen shot of that excel worksheet, a screen shot of the program and a zip file containing the source code.

Basically, in Excel i applied border bottom on merged cells with value "Maret 31, 2014" and "Juni 30, 2014" and save it to testjokoLinking2.xlsx.

Then i run my program to "see" the border bottom and border top of each cell.
I got the output like below that i dont like.
Basically many cells inside a merged cell containing "(in thousands)" has border top = thick even though i did not apply any border to them individually or as a merged cell.

Is there any reason why those cells have border top= thick when the cells above them have border bottom?

Here is what i see when i run my program.

Workbook opened using path successfully!
Row,Col: 1, 1 Border Bottom: None, Top: None Content: (),
Row,Col: 1, 2 Border Bottom: Thick, Top: None Content: (Maret 31, 2014),
Row,Col: 1, 3 Border Bottom: Thick, Top: None Content: (),
Row,Col: 1, 4 Border Bottom: None, Top: None Content: (),
Row,Col: 1, 5 Border Bottom: Thick, Top: None Content: (Juni 30, 2014),
Row,Col: 1, 6 Border Bottom: Thick, Top: None Content: (),
Row,Col: 1, 7 Border Bottom: None, Top: None Content: (),
Row,Col: 2, 1 Border Bottom: None, Top: None Content: (),
Row,Col: 2, 2 Border Bottom: None, Top: Thick Content: ((in thousands)),
Row,Col: 2, 3 Border Bottom: None, Top: Thick Content: (),
Row,Col: 2, 4 Border Bottom: None, Top: None Content: (),
Row,Col: 2, 5 Border Bottom: None, Top: Thick Content: (),
Row,Col: 2, 6 Border Bottom: None, Top: Thick Content: (),
Row,Col: 2, 7 Border Bottom: None, Top: None Content: (),
Row,Col: 3, 1 Border Bottom: None, Top: None Content: (),
Row,Col: 3, 2 Border Bottom: None, Top: None Content: (),
Row,Col: 3, 3 Border Bottom: None, Top: None Content: (),
Row,Col: 3, 4 Border Bottom: None, Top: None Content: (),
Row,Col: 3, 5 Border Bottom: None, Top: None Content: (),
Row,Col: 3, 6 Border Bottom: None, Top: None Content: (),
Row,Col: 3, 7 Border Bottom: None, Top: None Content: (),
Row,Col: 4, 1 Border Bottom: None, Top: None Content: (),
Row,Col: 4, 2 Border Bottom: None, Top: None Content: ($),
Row,Col: 4, 3 Border Bottom: None, Top: None Content: (123),
Row,Col: 4, 4 Border Bottom: None, Top: None Content: (),
Row,Col: 4, 5 Border Bottom: None, Top: None Content: ($),
Row,Col: 4, 6 Border Bottom: None, Top: None Content: (222),
Row,Col: 4, 7 Border Bottom: None, Top: None Content: (),

And here is my small program.

//////////////////////////////////////////////////////////////////////////
// Copyright 2001-2013 Aspose Pty Ltd. All Rights Reserved.
//
// This file is part of Aspose.Cells. The source code in this file
// is only intended as a supplement to the documentation, and is provided
// "as is", without warranty of any kind, either expressed or implied.
//////////////////////////////////////////////////////////////////////////
using System.IO;

using Aspose.Cells;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Globalization;
using Aspose.Cells.Rendering;
//using Aspose.Words;
using SaveFormat = Aspose.Cells.SaveFormat;

namespace OpeningFiles
{
public class Program
{

    <span style="color:blue;">private</span> <span style="color:blue;">string</span> _outputS = <span style="color:#a31515;">""</span>;
    <span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)
    {
        <span style="color:green;">// The path to the documents directory.</span>
        <span style="color:blue;">string</span> dataDir = <span style="color:#2b91af;">Path</span>.GetFullPath(<span style="color:#a31515;">"../../../Data/"</span>);


        <span style="color:#2b91af;">Workbook</span> workbook = <span style="color:blue;">new</span> <span style="color:#2b91af;">Workbook</span>(dataDir + <span style="color:#a31515;">"testjokoLinking2.xlsx"</span>);
        <span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">"Workbook opened using path successfully!"</span>);

        <span style="color:green;">//Aspose.Cells.Range range = workbook.Worksheets.GetRangeByName("Table_2");</span>

        <span style="color:#2b91af;">Worksheet</span> excelWorksheet = workbook.Worksheets[0];
        <span style="color:green;">//int newColumnStartIndex = range.FirstColumn + range.ColumnCount;</span>
        Aspose.Cells.<span style="color:#2b91af;">Cells</span> cells = excelWorksheet.Cells;

        <span style="color:blue;">for</span> (<span style="color:blue;">int</span> rowIndex = 1; rowIndex < 5; rowIndex++)
        {
            <span style="color:blue;">for</span> (<span style="color:blue;">int</span> columnIndex = 1; columnIndex <= 7; columnIndex++)
            {

                <span style="color:blue;">if</span> (excelWorksheet.Cells.GetColumnWidth(columnIndex) > 0.0)
                {
                    Aspose.Cells.<span style="color:#2b91af;">Cell</span> excelCell = cells[rowIndex, columnIndex];
                    <span style="color:#2b91af;">Console</span>.Write(<span style="color:#a31515;">"Row,Col: </span><span style="color:mediumseagreen;">{0}</span><span style="color:#a31515;">, </span><span style="color:mediumseagreen;">{1}</span><span style="color:#a31515;"> "</span>,rowIndex, columnIndex);

                        

                        Aspose.Cells.<span style="color:#2b91af;">Style</span> excelStyle = excelCell.GetStyle();

                        <span style="color:#2b91af;">Console</span>.Write(<span style="color:#a31515;">"Border Bottom: </span><span style="color:mediumseagreen;">{0}</span><span style="color:#a31515;">, "</span>, excelStyle.Borders[Aspose.Cells.<span style="color:#2b91af;">BorderType</span>.BottomBorder].LineStyle);

                        <span style="color:#2b91af;">Console</span>.Write(<span style="color:#a31515;">"Top: </span><span style="color:mediumseagreen;">{0}</span><span style="color:#a31515;"> "</span>, excelStyle.Borders[Aspose.Cells.<span style="color:#2b91af;">BorderType</span>.TopBorder].LineStyle);
                        <span style="color:#2b91af;">Console</span>.Write(<span style="color:#a31515;">"  Content: (</span><span style="color:mediumseagreen;">{0}</span><span style="color:#a31515;">),"</span>, excelCell.StringValue);    
                    <span style="color:#2b91af;">Console</span>.WriteLine();
                }
            }
        }
        

        workbook.Save(dataDir + <span style="color:#a31515;">"testjokoLinkingOut1.xlsx"</span>, <span style="color:#2b91af;">SaveFormat</span>.Xlsx);
    
    }
    
 
}

}


Let me know if you need more information.

Thanks.

joko.

Hi Joko,


Thank you for elaborating the problem.

Please note that cell borders are shared between the two adjacent cells therefore the API behavior to return the top border for merged cells C3~G3 is correct because it is according to the Excel application. You may confirm this by checking the cell borders using the Format Cell dialog in Excel application. In case of merged cells, the top border is shown as grayed out in the Border tab of the Format Cell dialog. If you un-merge the cells and inspect the borders again, you will notice that the cells C3, D3, F3 & G3 have the top border enabled. Please check the attached snapshots for your reference.