抱歉,如果这已经得到回答,但我已经看到很多类似的帖子,到目前为止没有任何帮助。
基本上,我正在构建一个应用程序,它采用 PowerPoint“模板”并替换来自数据库的文本和图像。大部分内容已完成,但我在替换图像时正在努力解决问题。该模板插入了大量空白图像,随时可以替换,它们都是方形的,因为它们只是占位符。我可以毫无问题地替换它们,但是根据我从数据库中提取的图像,新图像会垂直或水平拉伸。它基本上是填充占位符形状。
我必须承认我发现很难理解文档模型,所以也许我试图改变错误的东西,我曾试图改变 blip.parent.shape 的“范围”属性,但我在猜测和没有快乐。
以下是将图像换出的代码(归功于原作者 amos http://atakala.com/browser/Item.aspx?user_id=amos&dict_id=2291)。一旦图像到位或之前,我什至不确定在哪里尝试调整大小......任何帮助将不胜感激。我现在不担心实际大小,我可以自己计算,只是能够更改图像大小才是问题所在。
以及示例代码(可能不是那么有用),我已经链接到我的示例项目。样本和文件都应该放在 c:\test 中才能工作。它只是一些图像、c# 项目和 program.cs 文件,以及一个示例 PPTX 文件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using d = DocumentFormat.OpenXml.Drawing;
using System.IO;
namespace PPTX_Image_Replace_test
{
class Program
{
static void Main(string[] args)
{
TestImageReplace(@"C:\test\TestImageReplaceAndResize.pptx");
}
public static void TestImageReplace(string fileName)
{
// make a copy of the original and edit that
string outputFileName = Path.Combine(Path.GetDirectoryName(fileName), "New_" + Path.GetFileName(fileName));
File.Copy(fileName, …Run Code Online (Sandbox Code Playgroud) 如果这是一个简单的事情,但在阅读了几篇类似的帖子后,我似乎无法找到正确的答案。
我基本上想做的是复制计算一组记录的平均值的功能。
下面是一些简单的 SQL 来演示我想要达到的目的。
DECLARE @T TABLE(CountryID int, CategoryID int, ProductID int, Price float)
INSERT INTO @T VALUES
(1,20, 300, 10),
(1,20, 301, 11),
(1,20, 302, 12),
(1,20, 303, 13),
(1,30, 300, 21),
(1,30, 300, 22),
(1,30, 300, 23),
(1,30, 300, 24),
(2,20, 300, 5),
(2,20, 301, 6),
(2,20, 302, 7),
(2,20, 303, 8),
(2,30, 300, 9),
(2,30, 300, 8),
(2,30, 300, 7),
(2,30, 300, 6)
SELECT
*
, AVG(Price) OVER(PARTITION BY CountryID, CategoryID) AS AvgPerCountryCategory
FROM @t
Run Code Online (Sandbox Code Playgroud)
这给了我我需要的结果...... …