using System;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Interop.Excel;
using System.Collections.Generic;
using System.ComponentModel;
using sd = System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
namespace KPIPPTGenerate
{
public partial class AnalysisPPT : Form
{
public AnalysisPPT()
{
InitializeComponent();
}
private void AnalysisPPT_Load(object sender, EventArgs e)
{
Microsoft.Office.Interop.PowerPoint.Application PPTApp = (Microsoft.Office.Interop.PowerPoint.Application)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("91493441-5A91-11CF-8700-00AA0060263B")));
PPTApp.Visible = MsoTriState.msoTrue;
foreach (Presentation Presen in PPTApp.Presentations)
{
//this.IfOpen = 1;
if (Presen.FullName.Contains("MTD_Report_2017-09-17"))
{
MessageBox.Show("PPT Template is open, please close the PPT and rerun");
return;
}
}
//@"C:\Users\tao.liu\Desktop\MTD_Report_2017-09-17.pptx"
Presentation PPTtemplate = PPTApp.Presentations.Open(string.Concat(@"D:\company\New_Report_KPI\template\180322_KPI_temp.pptx"), MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= PPTtemplate.Slides.Count; i++)
{
//if (PPTtemplate.Slides[i].Shapes.Count <= 81)
//{
// continue;
//}
//int kkk = 1;
//i = 1;
//int jj = 2;
//object enti = PPTtemplate.Slides[i];
//Microsoft.Office.Interop.PowerPoint.Shape ennn = PPTtemplate.Slides[i].Shapes[kkk];
//ttt(ennn);
//Microsoft.Office.Interop.PowerPoint.Table ennnt = (Microsoft.Office.Interop.PowerPoint.Table)PPTtemplate.Slides[i].Shapes[kkk].Table;
//var enti3 = ennnt.Rows;
//var e2 = ennnt.Rows[1];
//var coon = e2.Cells[1];
//object ennn2 = PPTtemplate.Slides[i].Shapes[kkk].TextFrame2;
//object ennn3 = PPTtemplate.Slides[i].Shapes[kkk].TextFrame2.TextRange.Item(jj);
//Microsoft.Office.Interop.PowerPoint.Chart ennnChart = PPTtemplate.Slides[i].Shapes[1].Chart;
//object ennnChart1 = PPTtemplate.Slides[i].Shapes[kkk].Chart.ChartData;
//object ennnChart11 = PPTtemplate.Slides[i].Shapes[kkk].Chart.PlotArea;
////ennnChart.ChartData.Activate();
//object yy = ennnChart.ChartData.Workbook;
//Workbook gWorkbook = (Microsoft.Office.Interop.Excel.Workbook)((dynamic)ennnChart.ChartData.Workbook);
//gWorkbook.Application.Visible = false;
//Worksheet gWorksheet = (Worksheet)((dynamic)gWorkbook.Worksheets["Sheet1"]);
//object HHH = gWorksheet.Cells[2, 1];//名称
//int m = 2, n = 2;
//object HH2 = gWorksheet.Cells[m, n];//百分比
////以此类推
int temp1 = PPTtemplate.Slides[i].Shapes.Count;
for (int j = 1; j <= temp1; j++)
{
string ss = string.Empty;
try
{
if (j == 8 || j == 9 || j == 24 || j == 27 || j == 28 || j == 9 || j == 24)
{int kk = 1;
}
ss = PPTtemplate.Slides[i].Shapes[j].TextFrame2.TextRange.Text;
if (ss == "#" || ss == "%" || ss=="") {
Random ran = new Random();
ss = ran.Next(100000).ToString();
PPTtemplate.Slides[i].Shapes[j].TextFrame2.TextRange.Text = ss;
}
//bool flag = true;
//if (flag)
//{
// Microsoft.Office.Interop.PowerPoint.ColorFormat foreColor = PPTtemplate.Slides[i].Shapes[j].Fill.ForeColor;
// foreColor.RGB = Color.FromArgb(255, 80, 176, 0).ToArgb();
// Microsoft.Office.Interop.PowerPoint.ColorFormat argb = PPTtemplate.Slides[i].Shapes[j].Line.ForeColor;
// argb.RGB = Color.FromArgb(255, 80, 176, 0).ToArgb();
// PPTtemplate.Slides[i].Shapes[j].Flip(MsoFlipCmd.msoFlipVertical);
//}else
//{
// Microsoft.Office.Interop.PowerPoint.ColorFormat variable = PPTtemplate.Slides[i].Shapes[j].Fill.ForeColor;//红色
// variable.RGB = Color.FromArgb(255, 0, 0, 255).ToArgb();
// Microsoft.Office.Interop.PowerPoint.ColorFormat foreColor2 = PPTtemplate.Slides[i].Shapes[j].Line.ForeColor;
// foreColor2.RGB = Color.FromArgb(255, 0, 0, 255).ToArgb();
//}
//if (i==2&&j==81) {
// PPTtemplate.Slides[i].Shapes[j].Height = 12;
// PPTtemplate.Slides[i].Shapes[j].Top = 159;
//}
//double scale = PPTtemplate.Slides[i].Shapes[22].Chart.Axes(Microsoft.Office.Interop.PowerPoint.XlAxisType.xlValue, Microsoft.Office.Interop.PowerPoint.XlAxisGroup.xlPrimary).MaximumScale;
//dynamic height = PPTtemplate.Slides[i].Shapes[22].Height;
//double k = PPTtemplate.Slides[i].Shapes[22].Chart.PlotArea.InsideHeight / scale;
//dynamic top = PPTtemplate.Slides[i].Shapes[22].Top;
// float value = 20000;
//PPTtemplate.Slides[i].Shapes[36].Height = (float)(value * k);
// PPTtemplate.Slides[i].Shapes[36].Top = (float)(PPTtemplate.Slides[i].Shapes[22].Height + top+ - (value + 247599) * k);
//Microsoft.Office.Interop.PowerPoint.Chart ennnChart = PPTtemplate.Slides[i].Shapes[81].Chart;
//ennnChart.Legend
//Workbook gWorkbook = (Workbook)((dynamic)ennnChart.ChartData.Workbook);
//gWorkbook.Application.Visible = false;
//Worksheet gWorksheet = (Worksheet)((dynamic)gWorkbook.Worksheets["Sheet1"]);
//Range range = gWorksheet.get_Range("B2", "C4");
//ennnChart.SetSourceData(range);
//gWorkbook.ActiveChart.SetSourceData(gWorksheet.get_Range("A2", "B3"), Microsoft.Office.Interop.Excel.XlRowCol.xlColumns);
sb.AppendLine(string.Format("Slides {0},Shapes {1},textrange {2}", i, j, ss));
}
catch (Exception ex)
{
string s = ex.ToString();
try
{
for (int lt = 1; lt <= PPTtemplate.Slides[i].Shapes[j].TextFrame2.TextRange.Count; lt++)
{
var eded = PPTtemplate.Slides[i].Shapes[j].TextFrame2.TextRange.Item(lt).Text;
if (eded == "#" || eded == "%"|| eded == "")
{
Random ran = new Random();
eded = ran.Next(100000).ToString();
PPTtemplate.Slides[i].Shapes[j].TextFrame2.TextRange.Item(lt).Text = eded;
}
sb.AppendLine(string.Format("Slides {0},Shapes {1},Itemindex:{2} item_value {3}", i, j, lt, eded));
}
}
catch (Exception ee)
{
}
}
//try
//{ Color color = Color.FromArgb(255, 0, 192, 255);
// if (i==2&&j==2)//矩形边框
// SetBorderColor(i, j, color, PPTtemplate);
// if (i == 2 && j == 7)//六个圈
// SetBorderColor(i, j, color, PPTtemplate);
// ss = PPTtemplate.Slides[i].Shapes[j].TextFrame2.TextRange.Item(jj).Text;
// sb.AppendLine(string.Format("Slides {0},Shapes {1},textrange {2};TextFrame2.TextRange.Item({3})", i, j, ss,jj));
//}
//catch (Exception ex)
//{
//}
}
}
PPTtemplate.SaveAs(@"D:\company\New_Report_KPI\template\templateContent1.pptx", PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
PPTtemplate.Close();
File.WriteAllText(@"D:\company\New_Report_KPI\template\templatebmwpptborder1.txt", sb.ToString(), Encoding.Unicode);
}
private void ttt(object ennn)
{
Type en = ennn.GetType();
PropertyInfo[] ee = en.GetProperties();
foreach(PropertyInfo item in ee)
{
string name = item.Name;
object value = item.GetValue(ennn, null);
}
}
}
}
analysis PPT by com component 解析ppt
猜你喜欢
转载自www.cnblogs.com/duguzhenglong/p/9177230.html
今日推荐
周排行