Aspose.cells和aspose.slides

时间:2018-01-23 08:49:57

标签: excel powerpoint cells aspose

我对aspose完全不熟悉。请帮助我达到以下要求。 要求: - 我正在尝试创建一个可以处理excel文件的应用程序,并且基于excel数据应用程序将生成一个输出文件(ppt扩展名)。

特别说明: - 请注意我将提供ppt模板,该模板将有一个占位符,从上传的Excel中插入数据。

正在进行的工作: - 我已将Aspose.CellsAspose.Slides dll添加到我的项目中,并在PoC下面写了。

private void button1_Click(object sender, EventArgs e){
Workbook wb = new Workbook(@“C:\Users\Nilanjan\Desktop\Incident.xlsx”);
Worksheet ws = wb.Worksheets[0];
Cells cells = ws.Cells;
int col = CellsHelper.ColumnNameToIndex(“N”);
int last_row = ws.Cells.GetLastDataRow(col);
DataTable dt = wb.Worksheets[0].Cells.ExportDataTable(0, 0,
wb.Worksheets[0].Cells.MaxDataRow + 1, wb.Worksheets[0].Cells.MaxDataColumn + 1);
Presentation ps = new Presentation();
ISlide slide=ps.Slides[0];
slide=ps.Slides[1];
ps.Save(@“C:\Users\Nilanjan\Desktop\CocoonIncident1.pptx”,Aspose.Slides.Export.SaveFormat.Pptx );
}

直到现在我已经尝试将excel上传到我的代码中,并且在处理之后我能够使用excel数据填充DataTable,现在下一步是用该DataTable数据填充ppt-template。请帮助我实现此功能或请建议合适的解决方法。如果需要ppt模板或excel文件,请告诉我。

1 个答案:

答案 0 :(得分:0)

@Nilanjan,

I have observed your requirements for adding DataTable to PowerPoint slides. There is no direct way available to add DataTable in PowerPoint slides. You need to access every cell in DataTable and add that in PowerPoint slides by following mechanism supported by PowerPoint or Aspose.Slides. I suggest you to please try using following sample code on your end.

    public static void DataTableToSlides()
    {
        String path = @"C:\Aspose Data\";

        System.Data.DataTable table = new System.Data.DataTable();
        table.Columns.Add("Term", typeof(string));
        table.Columns.Add("Value", typeof(float));

        table.Rows.Add(@"Term 16", 1.5);
        table.Rows.Add(@"Term 15", 0.7);
        table.Rows.Add(@"Term 14", 0.7);
        table.Rows.Add(@"Term 13", 0.6);
        table.Rows.Add(@"Term 12", 0.6);


        Presentation pres = new Presentation();
        ISlide slide = pres.Slides[0];
        double[] colWidth = { 100, 100 };
        double[] rowHeight = { 40};// 40, 40,40,40,40 };//1 row additional to hold the headers

        ITable slidesTable = slide.Shapes.AddTable(100, 10, colWidth, rowHeight);
        slidesTable[0, 0].TextFrame.Text = table.Columns[0].ColumnName;
        slidesTable[1, 0].TextFrame.Text = table.Columns[1].ColumnName;

        for (int i=0;i<table.Rows.Count;i++)
        {
            DataRow row = table.Rows[i];
            slidesTable.Rows.AddClone(slidesTable.Rows[0], false);
            slidesTable[0, i + 1].TextFrame.Text = row[0].ToString();
            slidesTable[1, i + 1].TextFrame.Text = row[1].ToString();
        }

        pres.Save(path + "Saved.pptx",Aspose.Slides.Export.SaveFormat.Pptx);
    }

I am working as Support developer/ Evangelist at Aspose.

Many Thanks.