facebooktwittermenuarrow-up

GemBox Support Forum

Picture inside a single cell

I need to achieve the effect like on the following screenshot, can it be done:

1

My code like below:

public static bool ExportTest(string fullFileName, string sheetName, DataTable insertDataTable)
{
    ExcelFile excelFile = new ExcelFile();
    try
    {
        ExcelWorksheet sheet = excelFile.Worksheets.Add(sheetName);
        int i = 2;
        foreach (DataRow item in insertDataTable.Rows)
        {
            string url = item["Face"].ToString();
            sheet.Pictures.Add(url, "A" + i, 100, 100, LengthUnit.Pixel);
            sheet.Columns[0].Width = 100;
            sheet.Rows[i - 1].Height = 300;
            i++;
        }

        sheet.InsertDataTable(insertDataTable, new InsertDataTableOptions());
        excelFile.Save(fullFileName);
        return true;
    }
    catch
    {
        throw;
    }
}

Thank you!

Hi Tonfy,

By “effect” are you referring to placing the image inside a single cell?
If that’s the case, try this:

sheet.Pictures.Add(url, "A1", 100, 100, LengthUnit.Pixel);
sheet.Columns[0].SetWidth(100, LengthUnit.Pixel);
sheet.Rows[0].SetHeight(100, LengthUnit.Pixel);

Or perhaps this:

sheet.Pictures.Add(url,
    new AnchorCell(sheet.Columns[0], sheet.Rows[0], true),
    new AnchorCell(sheet.Columns[0], sheet.Rows[0], false));

sheet.Columns[0].SetWidth(100, LengthUnit.Pixel);
sheet.Rows[0].SetHeight(100, LengthUnit.Pixel);

Does this solve your issue?

Regards,
Mario