We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Strange borders

i try to create word document but it creates with borders (attach)
here my code

public static Document CreateVARDoc()
{
    Aspose.Words.License license = new Aspose.Words.License();

    license.SetLicense("Aspose.Total.lic");

    //Create a word document object with Aspose.Word
    Document doc = new Document();

    //Create builder for document object
    DocumentBuilder builder = new DocumentBuilder(doc);
    //builder.Font.Border.LineWidth = 0;
    //builder.Font.Border.LineStyle = LineStyle.None;

    createWordTopHeader(builder);

    string[] aTitles = { "Sales Person", "Email Address", "Commission" };
    DataSet dsVARS = new DataSet();
    DataSet dsSalesPeople = new DataSet();
    int iCurrentUserId = 0;
    int iCurrentVAR = 0;

    //SELECT all the VARS
    //string strVARSelect = "SELECT UserId, companyName, LastLoginDate, "
    // + "firstName + ’ ’ + lastName as name, "
    // + "CommissionVersions.resellerPercentage from [User], "
    // + "CommissionVersions where isReseller = 1 and "
    // + "CommissionVersions.commissionId = [User].CommissionId "
    // + "and CommissionVersions.effectiveDate < "
    // + Global.DateTimeToNumber(DateTime.Now) + " ORDER BY CommissionVersions.effectiveDate DESC";

    dsVARS = DatabaseHelper2008.SQL.storedProcedureSelect("spWeb\_GetVAR", Global.GetConn(), new string[] { "effectiveDate" }, new string[] { ROBOBAKMisc.DateHelper.DateTimeToNumber(DateTime.Now).ToString() });

    if (dsVARS.Tables[0].Rows.Count > 0)
    {
        foreach (DataRow row in dsVARS.Tables[0].Rows)
        {
            if (iCurrentVAR == 0 || iCurrentVAR != Convert.ToInt32(row["UserId"]))
            {
                iCurrentVAR = Convert.ToInt32(row["UserId"]);

                string strSalesSelect = "SELECT UserId, emailAddress, LastLoginDate, "
                    +"firstName + ’ ’ + lastName as name, SalesPersonCommission "
                    +"FROM [User] where ResellerId = " + row["UserId"].ToString()
                    +" and isSalesPerson = 1";

                dsSalesPeople = DatabaseHelper2008.SQL.storedProcedureSelect("spWeb\_GetSales", Global.GetConn(), new string[] { "resellerid" }, new string[] { row["UserId"].ToString() });

                if (dsSalesPeople.Tables[0].Rows.Count > 0)
                {
                    string strInfo = "VAR: " + row["companyName"].ToString()
                        +"\r\nCommission: " + row["resellerPercentage"].ToString() + " %";

                    //Create the first row with VAR info
                    createTableTopItems(aTitles, strInfo, builder);

                    foreach (DataRow rowUser in dsSalesPeople.Tables[0].Rows)
                    {
                        if (iCurrentUserId == 0 || iCurrentUserId != Convert.ToInt32(rowUser["UserId"]))
                        {
                            string[] aValues = {rowUser["name"].ToString(), rowUser["emailAddress"].ToString(),
                                rowUser["SalesPersonCommission"].ToString()};

                            createTableItems(aValues, builder, System.Drawing.Color.White);
                            iCurrentUserId = Convert.ToInt32(rowUser["UserId"]);
                        }
                    }
                }
            }
        }
    }

    //Create Footer
    createFooter(builder);

    return doc;
}

private static void createFooter(DocumentBuilder builder)
{
    createBorder(builder, false);
    builder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.FooterPrimary);

    builder.StartTable();
    double tableWidth = builder.PageSetup.PageWidth - builder.PageSetup.LeftMargin - builder.PageSetup.RightMargin;
    builder.Font.Size = 8;
    builder.InsertCell();
    builder.CellFormat.Width = tableWidth / 3;
    builder.InsertField("DATE", DateTime.Now.ToString());
    builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Left;
    builder.InsertCell();
    builder.CellFormat.Width = tableWidth / 3;
    builder.Write("© " + DateTime.Now.Year + " ROBOdrs LLC.");
    builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
    builder.InsertCell();
    builder.CellFormat.Width = tableWidth / 3;
    builder.Write("Page ");
    builder.InsertField("PAGE", "");
    builder.Write(" of ");
    builder.InsertField("NUMPAGES", "");
    builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right;
    builder.EndRow();
    builder.EndTable();
}

private static void createTableItems(string[] aValues, DocumentBuilder builder,
System.Drawing.Color rowColor)
{
    createBorder(builder, true);

    double tableWidth = builder.PageSetup.PageWidth - builder.PageSetup.LeftMargin - builder.PageSetup.RightMargin;

    for (int i = 0; i < aValues.Length; i++)
    {
        builder.InsertCell();
        builder.CellFormat.Shading.BackgroundPatternColor = rowColor;
        builder.CellFormat.HorizontalMerge = CellMerge.First;
        builder.CellFormat.BottomPadding = 5;
        //builder.CellFormat.Width = 130;
        builder.CellFormat.Width = tableWidth / aValues.Length;

        builder.Write(aValues[i].ToString());
    }

    builder.EndRow();
}

private static void createTableTopItems(string[] aTitles, string strCompany, DocumentBuilder builder)
{
    //Specify font formatting before adding text.
    builder.Font.Size = 8;
    builder.Font.Bold = true;
    builder.Font.Color = System.Drawing.Color.Black;
    builder.Font.Name = "Arial";
    double tableWidth = builder.PageSetup.PageWidth - builder.PageSetup.LeftMargin - builder.PageSetup.RightMargin;

    if (strCompany != "")
    {
        createBorder(builder, false);
        builder.InsertCell();
        builder.CellFormat.HorizontalMerge = CellMerge.First;
        builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.White;
        builder.CellFormat.Width = aTitles.Length \*130;
        //builder.CellFormat.Borders.LineStyle = LineStyle.None;
        builder.Write("\n" + strCompany + "\n");
        builder.EndRow();
    }

    builder.Font.Border.LineStyle = LineStyle.Single;

    //Center everything
    //builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;

    for (int i = 0; i < aTitles.Length; i++)
    {
        builder.InsertCell();
        builder.CellFormat.HorizontalMerge = CellMerge.First;
        builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.LightGray;
        builder.CellFormat.Width = tableWidth / aTitles.Length;
        builder.Write(aTitles[i]);
    }

    builder.EndRow();
    builder.Font.Bold = false;
}

main function is CreateVARDoc but all words in document has border as you see
how can i remove it?

Hi

Thanks for your request. These are borders of Paragraphs. I think that this caused by createBorder method. Could you please provide me code of this method?

Best regards.

here is method

private static void createBorder(DocumentBuilder builder, bool bAddBorder)
{
    Aspose.Words.Borders borders = builder.CellFormat.Borders;

    if (bAddBorder)
    {
        borders.LineStyle = LineStyle.Hairline;
        borders.LineWidth = 1;
        borders.Color = System.Drawing.Color.LightGray;
    }
    else
    {
        borders.LineStyle = LineStyle.None;
        borders.LineWidth = 0;
        borders.Color = System.Drawing.Color.LightGray;
    }
}

i try to edit it but borders is still present

Hi

Thanks you for additional information. I found the problem in your code. Problem is caused by the following line. (see createTableTopItems method)

builder.Font.Border.LineStyle = LineStyle.Single;

Just remove or comment this line. Hope this helps.

Best regards.

great!!! thanks it works!!