public async Task <bool> WriteDataFor100(String strID) { try { JObject jsonData = await RequestData.GetWxPPTData("164"); if (jsonData.Value <String>("code").Equals("200") && jsonData.Value <JObject>("data") != null) { JObject dataObj = jsonData["data"].ToObject <JObject>(); string pptdata = dataObj.Value <String>("pptdata"); JArray pptdataArr = JsonConvert.DeserializeObject <JArray>(pptdata); foreach (JObject jObject in pptdataArr) { string picUrl = jObject.Value <String>("picurl"); string content = jObject.Value <String>("content"); int index = (int)decimal.Parse(jObject.Value <string>("index")); PowerPoint.Shapes shapes = Globals.ThisAddIn.Application.ActivePresentation.Slides[index].Shapes; PowerPoint.Shape shape = PPTAPI.getShape(shapes, "pic_1"); if (shape != null) { if (!String.IsNullOrEmpty(picUrl)) { string strPath = Request.HttpDownload(picUrl).Result; shapes.AddPicture(strPath, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoCTrue, shape.Left, shape.Top, shape.Width, shape.Height); shape.Delete(); } } shape = PPTAPI.getShape(shapes, "text_1"); if (shape != null) { shape.TextFrame.TextRange.Text = jObject.Value <String>("content"); } } } else { return(false); } } catch { } return(true); }
public async Task <bool> WriteData(String strID) { PowerPoint.Shapes shapes = Globals.ThisAddIn.Application.ActivePresentation.Slides[1].Shapes; try { JObject jsonData = await RequestData.GetPredictData(strID); JObject dataObj = jsonData["data"].ToObject <JObject>(); PowerPoint.Shape shape = PPTAPI.getShape(shapes, "Label_1"); if (shape != null) { shape.TextFrame.TextRange.Text = dataObj.Value <String>("labelInfo"); } shape = PPTAPI.getShape(shapes, "DateLabel"); if (shape != null) { String strText = shape.TextFrame.TextRange.Text; strText = strText.Replace("{Date}", dataObj.Value <String>("date")); shape.TextFrame.TextRange.Text = strText; } shape = PPTAPI.getShape(shapes, "Table_1"); if (shape != null) { PowerPoint.Table table = shape.Table; shape = PPTAPI.getShape(shapes, "Chart_1"); PowerPoint.Chart chart = shape.Chart; var ws = chart.ChartData.Workbook.Worksheets[1]; JArray array = dataObj.Value <JArray>("salesData"); List <PredictData> predicts = CoreAPI.Deserialize <List <PredictData> >(array.ToString()); int col = 2; char colStart = 'B'; foreach (PredictData predict in predicts) { int row = 1; String step = colStart + row.ToString(); ws.Range[step].Value = predict.Month; table.Cell(row, col).Shape.TextFrame.TextRange.Text = predict.Sales; row++; step = colStart + row.ToString(); ws.Range[step].Value = predict.Sales; table.Cell(row, col).Shape.TextFrame.TextRange.Text = predict.Ratio; row++; step = colStart + row.ToString(); ws.Range[step].Value = predict.Ratio; col++; colStart++; } } shape = PPTAPI.getShape(shapes, "Image_1"); if (shape != null) { String strUrl = dataObj.Value <String>("imageUrl"); if (!String.IsNullOrEmpty(strUrl)) { string strPath = Request.HttpDownload(strUrl).Result; shapes.AddPicture(strPath, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoCTrue, shape.Left, shape.Top, shape.Width, shape.Height); shape.Delete(); } } } catch { } return(true); }
public async Task <bool> WriteDataFor164() { try { JObject jsonData = await RequestData.GetPredictData("164"); if (jsonData.Value <String>("code").Equals("200") && jsonData.Value <JObject>("data") != null) { JObject dataObj = jsonData["data"].ToObject <JObject>(); string mbnrStr = dataObj.Value <String>("mbnr"); JArray mbnrArr = JsonConvert.DeserializeObject <JArray>(mbnrStr); foreach (JObject jObject in mbnrArr) { if (jObject.Value <String>("index").Equals("3")) { PowerPoint.Shapes shapes = Globals.ThisAddIn.Application.ActivePresentation.Slides[3].Shapes; JObject tableObj = jObject.Value <JObject>("table"); PowerPoint.Shape shape = PPTAPI.getShape(shapes, "table_1"); if (shape != null) { PowerPoint.Table table = shape.Table; shape = PPTAPI.getShape(shapes, "chart_1"); PowerPoint.Chart chart = shape.Chart; var ws = chart.ChartData.Workbook.Worksheets[1]; JArray tb1 = tableObj.Value <JArray>("tb1"); int col = 2; char colStart = 'B'; for (int i = 0; i < tb1.Count(); i++) { int row = 1; String step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c1"); table.Cell(row, col).Shape.TextFrame.TextRange.Text = tb1[i].Value <String>("c2");; row++; step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c2");; table.Cell(row, col).Shape.TextFrame.TextRange.Text = tb1[i].Value <String>("c3");; row++; step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c3");; col++; colStart++; } } } else if (jObject.Value <String>("index").Equals("4")) { PowerPoint.Shapes shapes = Globals.ThisAddIn.Application.ActivePresentation.Slides[4].Shapes; JObject tableObj = jObject.Value <JObject>("table"); PowerPoint.Shape shape = PPTAPI.getShape(shapes, "chart_1"); if (shape != null) { PowerPoint.Chart chart = shape.Chart; var ws = chart.ChartData.Workbook.Worksheets[1]; JArray tb1 = tableObj.Value <JArray>("tb1"); int col = 2; char colStart = 'B'; for (int i = 0; i < tb1.Count(); i++) { int row = 1; String step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c1"); row++; step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c2");; row++; step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c3");; col++; colStart++; } } shape = PPTAPI.getShape(shapes, "chart_2"); if (shape != null) { PowerPoint.Chart chart = shape.Chart; var ws = chart.ChartData.Workbook.Worksheets[1]; JArray tb1 = tableObj.Value <JArray>("tb2"); int col = 2; char colStart = 'B'; for (int i = 0; i < tb1.Count(); i++) { int row = 1; String step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c1"); row++; step = colStart + row.ToString(); string[] lsArr = tb1[i].Value <String>("c2").Split(','); int length = lsArr.Length; if (length < 5) { Array.Resize(ref lsArr, 5); } for (int j = length; j < 5; j++) { lsArr[j] = "0.0%"; } ws.Range[step].Value = lsArr[0]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[1]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[2]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[3]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[4]; col++; colStart++; } } } else if (jObject.Value <String>("index").Equals("5")) { PowerPoint.Shapes shapes = Globals.ThisAddIn.Application.ActivePresentation.Slides[5].Shapes; JObject tableObj = jObject.Value <JObject>("table"); PowerPoint.Shape shape = PPTAPI.getShape(shapes, "chart_1"); if (shape != null) { PowerPoint.Chart chart = shape.Chart; var ws = chart.ChartData.Workbook.Worksheets[1]; JArray tb1 = tableObj.Value <JArray>("tb1"); int col = 2; char colStart = 'B'; for (int i = 0; i < tb1.Count(); i++) { int row = 1; String step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c1"); row++; step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c2");; row++; step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c3");; col++; colStart++; } } shape = PPTAPI.getShape(shapes, "chart_2"); if (shape != null) { PowerPoint.Chart chart = shape.Chart; var ws = chart.ChartData.Workbook.Worksheets[1]; JArray tb1 = tableObj.Value <JArray>("tb2"); int col = 2; char colStart = 'B'; for (int i = 0; i < tb1.Count(); i++) { int row = 1; String step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c1"); row++; step = colStart + row.ToString(); string[] lsArr = tb1[i].Value <String>("c2").Split(','); int length = lsArr.Length; if (length < 5) { Array.Resize(ref lsArr, 5); } for (int j = length; j < 5; j++) { lsArr[j] = "0.0%"; } ws.Range[step].Value = lsArr[0]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[1]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[2]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[3]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[4]; col++; colStart++; } } } else if (jObject.Value <String>("index").Equals("6")) { PowerPoint.Shapes shapes = Globals.ThisAddIn.Application.ActivePresentation.Slides[6].Shapes; JObject tableObj = jObject.Value <JObject>("table"); PowerPoint.Shape shape = PPTAPI.getShape(shapes, "chart_1"); if (shape != null) { PowerPoint.Chart chart = shape.Chart; var ws = chart.ChartData.Workbook.Worksheets[1]; JArray tb1 = tableObj.Value <JArray>("tb1"); int col = 2; char colStart = 'B'; for (int i = 0; i < tb1.Count(); i++) { int row = 1; String step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c1"); row++; step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c2");; row++; step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c3");; col++; colStart++; } } shape = PPTAPI.getShape(shapes, "chart_2"); if (shape != null) { PowerPoint.Chart chart = shape.Chart; var ws = chart.ChartData.Workbook.Worksheets[1]; JArray tb1 = tableObj.Value <JArray>("tb2"); int col = 2; char colStart = 'B'; for (int i = 0; i < tb1.Count(); i++) { int row = 1; String step = colStart + row.ToString(); ws.Range[step].Value = tb1[i].Value <String>("c1"); row++; step = colStart + row.ToString(); string[] lsArr = tb1[i].Value <String>("c2").Split(','); int length = lsArr.Length; if (length < 5) { Array.Resize(ref lsArr, 5); } for (int j = length; j < 5; j++) { lsArr[j] = "0.0%"; } ws.Range[step].Value = lsArr[0]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[1]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[2]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[3]; row++; step = colStart + row.ToString(); ws.Range[step].Value = lsArr[4]; col++; colStart++; } } } } } else { return(false); } } catch { } return(true); }