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

Free Support Forum - aspose.com

Columnspan- problem with move columns

Hi


I have problem with my table.
My table have a few empty cells, in 2nd column.

I use:
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i][2].ToString() == “”)
{
t.Rows[i].Cells[1].ColumnsSpan = 2;
}
}
My columns became merge, but 2nd column moved on 3rd column , and 3rd column moved 4th column , etc. (Moved to the right)

I don’t want it.
How can I:
Delete 2nd column which is empty, copy content from 4th column to 3rd column or there is other solution?

Columns 3,4,5 etc should stay for their places.


Hi Michal,

Thanks for contacting support.

Can you please share the complete code snippet, so that we can try replicating the issue in our environment. We are sorry for this inconvenience.
Now i have: After.JPG
Before columnspan i have: Before.JPG

Good.JPG show how would be good. 3rd, 4th, 5th column etc stayed on their place.
{
m_gen = new Aspose.Pdf.Generator.Pdf();
m_sec = m_gen.Sections.Add();
System.Data.DataTable tab = new System.Data.DataTable(tablename);
tab.ExtendedProperties.Add("Spalten", Spalten);
tab.ExtendedProperties.Add("Rahmen", Rahmen);
for (int i = 0; i < Columns; i++)
{
tab.Columns.Add(i.ToString());
}
m_Tables.Tables.Add(tab);
string[] fld = fields.Split('¶');
m_Tables.Tables[tablename].Rows.Add(fld);
return "1";

System.Data.DataTable dt = m_Tables.Tables[tablename];
Table t = new Table();

t.ImportDataTable(dt, false, 0, 0, dt.Rows.Count, dt.Columns.Count-1);
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i][2].ToString() == "")
{
t.Rows[i].Cells[1].ColumnsSpan = 2;
}
}
}

Hi Michal,


Thanks for sharing the details.

I have tried executing the code snippet which you have shared but there are many variables which are not defined. Furthermore, I have observed that you are using legacy Aspose.Pdf.Generator and there might be some issues when using older approach. However in order to replicate the issue, I have tried using following code snippet based on new Document Object Model and I am unable to notice any issue. Can you please try using latest DOM and in case you still face any issue, please share complete code snippet so that we can again try replicating the issue in our environment. We are sorry for your inconvenience.

[C#]

DataTable dt = new
DataTable(“Employee”);<o:p></o:p>

dt.Columns.Add("Employee_ID", typeof(Int32));

dt.Columns.Add("Employee_Name", typeof(string));

dt.Columns.Add("Gender", typeof(string));

//Add 2 rows into the DataTable object programmatically

DataRow dr = dt.NewRow();

dr[0] = 1;

dr[1] = "John Smith";

dr[2] = "Male";

dt.Rows.Add(dr);

dr = dt.NewRow();

dr[0] = 2;

dr[1] = "Mary Miller";

dr[2] = "Female";

dt.Rows.Add(dr);

// Create Document instance

Document doc = new Document();

doc.Pages.Add();

// Initializes a new instance of the Table

Aspose.Pdf.Table table = new Aspose.Pdf.Table();

//Set column widths of the table

table.ColumnWidths = "40 100 100 100";

// Set the table border color as LightGray

table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

// set the border for table cells

table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

table.ImportDataTable(dt, true, 0, 1, 3, 3);

for (int i = 0; i < dt.Rows.Count; i++)

{

if (dt.Rows[i][2].ToString() == "")

{

table.Rows[i].Cells[1].ColSpan = 2;

}

}

// Add table object to first page of input document

doc.Pages[1].Paragraphs.Add(table);

// Save updated document containing table object

doc.Save(“c:/pdftest/DataIntegrated.pdf”);

Hi, thanks for your answer.


I tested your code, but it works the same as my code.
{
table.Rows[i].Cells[1].ColSpan = 2;
}

This code merge columns (1 and 2) very good, but columns (2,3,4 etc) move a 1 position to the right. I want to them not shifted.

I insert picture witch show how my table look.

Hi Michal,


Thanks for sharing the details.

I can see the problem related to columns movement. However in order to resolve this issue, we need to first replicate it in our environment. Can you please share some sample project so that we can test the scenario in our environment. We are sorry for this inconvenience.

Hi,


Please test this code, it works the same as my code.

{

// The path to the documents directory.
string dataDir = Path.GetFullPath("…/…/…/Data/");

// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);

DataTable dt = new DataTable(“Employee”);
dt.Columns.Add(“Employee_ID”, typeof(Int32));
dt.Columns.Add(“Employee_Name”, typeof(string));
dt.Columns.Add(“Gender”, typeof(string));
dt.Columns.Add(“Test”, typeof(string));
//Add 2 rows into the DataTable object programmatically
DataRow dr = dt.NewRow();
dr[0] = 1;
dr[1] = “John Smith”;
dr[2] = “test”;
dr[3] = “”;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 2;
dr[1] = “Mary Miller”;
dr[2] = “Female”;
dr[3] = “123”;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 2;
dr[1] = “”;
dr[2] = “Female”;
dr[3] = “123”;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 3;
dr[1] = “Mary Miller”;
dr[2] = “Female”;
dr[3] = “123”;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 4;
dr[1] = “”;
dr[2] = “Female”;
dr[3] = “123”;
dt.Rows.Add(dr);
// Create Document instance
Document doc = new Document();
doc.Pages.Add();
// Initializes a new instance of the Table
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
//Set column widths of the table
table.ColumnWidths = “40 100 100 100”;
// Set the table border color as LightGray
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// set the border for table cells
table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
table.ImportDataTable(dt, false, 0, 0, dt.Rows.Count, dt.Columns.Count);
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i][1].ToString() == “”)
{
table.Rows[i].Cells[0].ColSpan = 2;
}
}
// Add table object to first page of input document
doc.Pages[1].Paragraphs.Add(table);
// Save updated document containing table object
//doc.Save(“c:/pdftest/DataIntegrated.pdf”);

doc.Save(dataDir+ “IsNewPageProperty_Test.pdf”);
System.Diagnostics.Process.Start(dataDir + “IsNewPageProperty_Test.pdf”);
}

Hi Michal,


Thanks for sharing the details.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWNET-39979 in our issue tracking system. We will
further look into the details of this problem and will keep you updated on the
status of correction. Please be patient and spare us little time. We are sorry
for this inconvenience.