Gantt chart using aspose with .net 1.1

We have to make a Gantt chart report in PDF using asp.net 1.1. Please see the attached excel in print preview mode. The PDF should look exactly like the attached Excel in print preview mode.

Here is the requirement summery:-

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

  1. Date range will be vary upto maximum of two years ( 24 Months max).
  2. I have to repeat the header rows (showing the year and months) in every page.
  3. There could be N number of rows for displaying program data (like row 3 to 13 in excel) for a particular site.
  4. Number of site is also not fixed (shown as site 1, site 2 in excel). This will come as a input condition.
  5. The color and dotted background will be decided dynamically. As per database values.

Currently the approach we thought is using Aspose.Words. and on the fly we will insert tables and cell and we will give borders and width to a particular cell but it appears very difficult to code and manage.

Do you have any other suggestion. Can we do it directly using Aspose.PDFs or Aspose.Cells? Which one will be easier to code? Please suggest. Please share some code snippet or sample demo.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your interest in Aspose products. If you already have such chart in Excel and just need to convert this chart to PDF, you can try using Aspose.Cells. Aspose.Cells provides a functionality to convert Excel spreadsheets to PDF.

If you need to generate such reports from scratch using Aspose.Words, I think, you can try using mail merge approach. The latest version of Aspose.Words supports nested regions upon mail merge so theoretically it is possible to generate such complex reports with parent-child relationships. But I cannot promise you that code and template will be simple. If you need I can try to create you sample code and template, but this will take some time because your report is quite complex.

Also as alternative way of generating such reports, you can consider Aspose.Cells. You can contact Aspose.Cells support in the corresponding forum.

Best regards.

Thanks for the reply,

But we have to build ther report from the scratch. I will contact aspsose.cell also but i think they wont be able to provide the the page break logic as I mentioned in my requirment.(like the top two header row will get repeted in everypage).

In the mean time can you share some gantt chart sample code using aspose.words? I believe gantt chart is a common reqirement across the projects. My report is also a simple gantt chart only having the date range and other data as input parameters.

Thanks,

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Could you also provide me sample data source, you use to generate such chart? This will help me to create a code example.

Best regards.

hi

Please refer to sample excel wich I have provided earlier for the samaple data. Data will come as a data set which will have site, start date, end date and other information rowwise as given in the excel.

This is a more closer look how data will be there in the dataset :-

site1 startdate1 program1 enddate1

site1 startdate2 program2 enddate2

site1 startdate3 program3 enddate3..... there could be number of rows for a site...

site2 startdate1 program1 enddate1

site2 startdate2 program2 enddate2 ..... and so on...

data will be grouped by site as you can see in the attached excel also.....

hope this will help.....

Thanks,

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I created a simple example for you. Hope it could be useful. Here is code:

DataSet ds = GetData();

// Open template.

Document doc = new Document(@"Test001\in.doc");

// Add MergeField event handler.

// It will allowus to change table formatign upon mail merge process.

doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField);

// Execute mail merge with regions.

doc.MailMerge.ExecuteWithRegions(ds);

// Save output document.

doc.Save(@"Test001\out.doc");

doc.Save(@"Test001\out.pdf");

=====================================================================

void MailMerge_MergeField(object sender, MergeFieldEventArgs e)

{

if (e.FieldName == "StartDate")

{

startDate = (DateTime) e.FieldValue;

}

else if (e.FieldName == "EndDate")

{

DateTime endDate = (DateTime) e.FieldValue;

int duration = endDate.Month - startDate.Month;

// If duration is greater then we should merge cells.

// Get cell where the currrent mergefield is located.

Cell refCell = (Cell) e.Field.Start.GetAncestor(NodeType.Cell);

if (refCell != null)

{

// Merge cells.

refCell.CellFormat.HorizontalMerge = CellMerge.First;

for (int i = 0; i < duration; i++)

{

if (refCell.NextSibling != null)

{

refCell = (Cell) refCell.NextSibling;

refCell.CellFormat.HorizontalMerge = CellMerge.Previous;

}

}

// We should also merge other cells in row.

refCell = (Cell) refCell.NextSibling;

if (refCell != null)

{

refCell.CellFormat.HorizontalMerge = CellMerge.First;

while (refCell.NextSibling != null)

{

refCell = (Cell) refCell.NextSibling;

refCell.CellFormat.HorizontalMerge = CellMerge.Previous;

}

}

}

}

}

private DateTime startDate;

private DataSet GetData()

{

// Prepare dummy data.

DataSet ds = new DataSet();

int numberOfSites = 3;

DataTable sites = new DataTable("Sites");

sites.Columns.Add("SiteId");

sites.Columns.Add("SiteName");

for (int i = 0; i < numberOfSites; i++)

sites.Rows.Add(new object[] {i, string.Format("site_{0}", i)});

ds.Tables.Add(sites);

DataTable programs = new DataTable("Programs");

programs.Columns.Add("SiteId");

programs.Columns.Add("ProgId");

programs.Columns.Add("ProgName");

programs.Columns.Add("StartDate", typeof (DateTime));

programs.Columns.Add("EndDate", typeof (DateTime));

// In the template we have one region per month.

// So in our datasource we also should have one table per month.

// You can achieve the same usingstored proc.

Random rnd = new Random();

for (int month = 1; month <= 12; month++)

{

DataTable monthData = programs.Clone();

monthData.TableName = month.ToString();

for (int siteId = 0; siteId < numberOfSites; siteId++)

{

int numberOfPrograms = rnd.Next(1, 4);

for (int j = 0; j < numberOfPrograms; j++)

{

int endMonth = rnd.Next(month, 12);

monthData.Rows.Add(new object[]

{

siteId, string.Format("{0}{1}", siteId, j),

string.Format("Prog_{0}_{1}", siteId, j),

new DateTime(2010, month, 1), new DateTime(2010, endMonth, 1)

});

}

}

ds.Tables.Add(monthData);

ds.Relations.Add(sites.Columns["SiteId"], monthData.Columns["SiteId"]);

}

return ds;

}

Sample template and output documents are attached.

Best regards.

I want to use page break every after 23 rows for that I am using code workBook.Worksheets[0].VPageBreaks.Add(23,97); but its not working. Please let us know if there is any other way to do this.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. It seems your question is related to Aspose.Cells. So I will move your request to the appropriate forum. My colleagues will answer you shortly.

Best regards.

Hi,

Well, the code segment i.e. “workBook.Worksheets[0].VPageBreaks.Add(23,97);” works fine normally.
But, it (inserting page breaks) won’t work if you have set Fit to pages tall/wide in the page setup options. This behavior is same as MS Excel and you may confirm it by manually performing the steps in MS Excel. For your need, you should not use Fit to Pages tall/wide options if you want to insert pages breaks at your desired locations.

Kindly let us know if you still have any issue. We will be glad to sort it out.

Thank you.

before saving the excel file I want to count the number of pages of worksheet. How can i do that?

Hi,

Well, you may use SheetRender.PageCount attribute,

e.g
ImageOrPrintOptions printoption = new ImageOrPrintOptions();
printoption.PrintingPage = PrintingPageType.Default;
SheetRender sr = new SheetRender(worksheet, printoption);
int pageCount = sr.PageCount;


Thank you.


Alternatively, you may also use Worksheet.GetPrintingPageBreaks(ImageOrPrintOptions options) method, e.g

CellArea [] area = worksheet.GetPrintingPageBreaks(printoption);
int length = area.Length;


Thanks,

thanks for your reply page count is ok now i have page count so can I count the number rows and read the data from each page. If yes then how please give me the solutions.

ImageOrPrintOptions printoption = new ImageOrPrintOptions();
printoption.PrintingPage = PrintingPageType.Default;
SheetRender sr = new SheetRender(worksheet, printoption);
int pageCount = sr.PageCount; and

CellArea [] area = worksheet.GetPrintingPageBreaks(printoption);
works for the latest version but i am using old one 7.0.0.0

Please give me the another solution for this version

Hi,

Well, SheetRender and other API such as, Worksheet.GetPrintingPageBreaks() are the latest api that we included in the recent versions, so, I am afraid, you got to use the latest version only to make use of the apis.

Thanks for your understanding!