刷新幻灯片母版视图

时间:2013-12-14 11:56:51

标签: c# office-interop

我正在从数据库更新powerpoint 2010幻灯片(可自动调整的形状类型)上的表格数据。我正在使用chart.Refresh成功刷新包含图表的幻灯片母版(msochart)。我想对表格类型的形状做同样的事情。但是对于表没有刷新方法,并且在主幻灯片视图上成功更新后,我的幻灯片母版视图不会刷新(更新)。 我正在使用C#4.0 interop for office 2010.
知道如何刷新表格幻灯片主视图吗? http://office.microsoft.com/en-001/powerpoint-help/what-is-a-slide-master-HA010280572.aspx

1 个答案:

答案 0 :(得分:0)

找到解决方案。当没有刷新方法时,我做了一个黑客攻击:  sh.Width = sh.Width + 1;  sh.Width = sh.Width - 1;

   public void UpdateTable(Shape sh, System.Data.DataTable dt)
    {
        try
        {
            //Supprimer toutes les lignes existantes
            if (sh.Table.Rows.Count >= 3)
            {
                int rowCount = sh.Table.Rows.Count;
                for (int i = 3; i <= rowCount; i++)
                {
                    sh.Table.Rows[sh.Table.Rows.Count].Delete();
                }

                //Vider le contenu de la première ligne
                for (int j = 1; j < sh.Table.Columns.Count; j++)
                {
                    sh.Table.Cell(2, j).Shape.TextFrame.TextRange.Text = "";
                }
            }

            //Parcourir les lignes
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sh.Table.Rows.Add(sh.Table.Rows.Count);
                //Parcourir les colonnes
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    sh.Table.Cell(i + 2, j + 1).Shape.TextFrame.TextRange.Text = dt.Rows[i][j].ToString();
                }
            }
            sh.Table.Rows[sh.Table.Rows.Count].Delete();

            sh.Width = sh.Width + 1;
            sh.Width = sh.Width - 1;

            Marshal.ReleaseComObject(sh);
        }
        catch (Exception exp)
        {
            Logger.Error(exp);
        }

    } 
相关问题