创建 ImagePart 并不将关系保存在 OpenXML 中

2023-11-25

--更新以提供完整的工人阶级示例,以及 2 个示例文档--

www.sklinar.co.uk/wp-content/uploads/mydoc.docx- 原始文档包含 INCLUDETEXT 指令以合并到 Footer.Docx 中

www.sklinar.co.uk/wp-content/uploads/footer.docx

我添加了一个ImagePart到我的文档以及使用FeedData()为其提供流媒体内容。

但我能在我的文档中看到的只是一个红色框。

我的初始代码创建了一个Run with a Drawing因为它是孩子:

--对于这个例子,我使用了硬编码的 FileStream 来清除可疑的图像--

为了使其正常工作,我每次都使用相同的页脚,并且当前使用正确的页脚进行硬编码:

runToAmend.InsertAfterSelf(CreateImageRun(sourceDocument,run,target.MainDocumentPart.FooterParts.ElementAt(2)));

The runToAmend取自当前文档中的运行 - 它包含一个字段,然后将其删除,并将图片(以及从另一个文档中获取的其他文本)放置在其位置。

    public Run CreateImageRun(WordprocessingDocument sourceDoc,  Run sourceRunFromOriginalDocument, FooterPart footerPart)
    {
        ImageData shape = sourceRun.Descendants<ImageData>().FirstOrDefault();

        ImagePart p = sourceDoc.MainDocumentPart.GetPartById(shape.RelationshipId) as ImagePart;

        ImagePart newPart = footerPart.AddImagePart(ImagePartType.Jpeg);

        using (Stream stream = new FileStream(@"C:\Users\SAS\Desktop\IMG_20130803_104521.jpg",FileMode.Open,FileAccess.Read))
        {
            stream.Position = 0;
            newPart.FeedData(stream);
        }

        string partId = footerPart.GetIdOfPart(newPart);

        Drawing newImage = CreateImage(partId);
        return new Run(newImage);
    }

Code to Create Drawing

private Drawing CreateImage(string relationshipId)
    {
        // Define the reference of the image.
        return new Drawing(
                 new DW.Inline(
                     new DW.Extent() { Cx = 990000L, Cy = 792000L },
                     new DW.EffectExtent()
                     {
                         LeftEdge = 0L,
                         TopEdge = 0L,
                         RightEdge = 0L,
                         BottomEdge = 0L
                     },
                     new DW.DocProperties()
                     {
                         Id = (UInt32Value)1U,
                         Name = "Picture 1"
                     },
                     new DW.NonVisualGraphicFrameDrawingProperties(
                         new A.GraphicFrameLocks() { NoChangeAspect = true }),
                     new A.Graphic(
                         new A.GraphicData(
                             new PIC.Picture(
                                 new PIC.NonVisualPictureProperties(
                                     new PIC.NonVisualDrawingProperties()
                                     {
                                         Id = (UInt32Value)0U,
                                         Name = "New Bitmap Image.jpg"
                                     },
                                     new PIC.NonVisualPictureDrawingProperties()),
                                 new PIC.BlipFill(
                                     new A.Blip(
                                         new A.BlipExtensionList(
                                             new A.BlipExtension()
                                             {
                                                 Uri =
                                                   "{28A0092B-C50C-407E-A947-70E740481C1C}"
                                             })
                                     )
                                     {
                                         Embed = relationshipId,
                                         CompressionState =
                                         A.BlipCompressionValues.Print
                                     },
                                     new A.Stretch(
                                         new A.FillRectangle())),
                                 new PIC.ShapeProperties(
                                     new A.Transform2D(
                                         new A.Offset() { X = 0L, Y = 0L },
                                         new A.Extents() { Cx = 990000L, Cy = 792000L }),
                                     new A.PresetGeometry(
                                         new A.AdjustValueList()
                                     ) { Preset = A.ShapeTypeValues.Rectangle }))
                         ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })
                 )
                 {
                     DistanceFromTop = (UInt32Value)0U,
                     DistanceFromBottom = (UInt32Value)0U,
                     DistanceFromLeft = (UInt32Value)0U,
                     DistanceFromRight = (UInt32Value)0U,
                     EditId = "50D07946"
                 });
    }

生成的 XML 显示正确,并且图像被添加到/Media/ folder.

<w:r>
  <w:drawing>
    <wp:inline distT="0" distB="0" distL="0" distR="0" wp14:editId="50D07946">
      <wp:extent cx="990000" cy="792000" />
      <wp:effectExtent l="0" t="0" r="0" b="0" />
      <wp:docPr id="1" name="Picture 1" />
      <wp:cNvGraphicFramePr>
        <a:graphicFrameLocks noChangeAspect="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />
      </wp:cNvGraphicFramePr>
      <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
        <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
          <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
            <pic:nvPicPr>
              <pic:cNvPr id="0" name="New Bitmap Image.jpg" />
              <pic:cNvPicPr />
            </pic:nvPicPr>
            <pic:blipFill>
              <a:blip r:embed="Raae77c5adb2e48f3" cstate="print">
                <a:extLst>
                  <a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}" />
                </a:extLst>
              </a:blip>
              <a:stretch>
                <a:fillRect />
              </a:stretch>
            </pic:blipFill>
            <pic:spPr>
              <a:xfrm>
                <a:off x="0" y="0" />
                <a:ext cx="990000" cy="792000" />
              </a:xfrm>
              <a:prstGeom prst="rect">
                <a:avLst />
              </a:prstGeom>
            </pic:spPr>
          </pic:pic>
        </a:graphicData>
      </a:graphic>
    </wp:inline>
  </w:drawing>
</w:r>

我花了大约 2 天的时间搜索 SO,Google MS 的糟糕文档。

public class WordTest
    {
        using DocumentFormat.OpenXml;
        using DocumentFormat.OpenXml.Packaging;
        using DocumentFormat.OpenXml.Vml;
        using DocumentFormat.OpenXml.Wordprocessing;
        using System;
        using System.Collections.Generic;
        using System.Drawing;
        using System.IO;
        using System.Linq;
        using A = DocumentFormat.OpenXml.Drawing;
        using DW = DocumentFormat.OpenXml.Drawing.Wordprocessing;
        using PIC = DocumentFormat.OpenXml.Drawing.Pictures;
        public void MethodName()
        {
            WordprocessingDocument mainDoc = WordprocessingDocument.Open("mydoc.docx", true);

            foreach (var item in mainDoc.MainDocumentPart.FooterParts)
            {
                ProcessParaIncludeTextMerge(item, item.Footer.Descendants<Run>(), mainDoc);
                item.Footer.Save();
            }

            mainDoc.MainDocumentPart.Document.Save();

        }

        private void ProcessParaIncludeTextMerge(OpenXmlPart part, IEnumerable<Run> runs, WordprocessingDocument originalDocument)
        {
            List<Run> paraRuns = runs.ToList();

            int runCount = paraRuns.Count();

            for (int i = 0; i < runCount; i++)
            {
                Run r = paraRuns.ElementAt(i);

                // check if this is a simple Merge Field
                if (r.HasChildren && r.Descendants<FieldCode>().Any())
                {
                    FieldCode code = r.Descendants<FieldCode>().First();

                    // we check the first fieldcode is a merge field - but we can't *just* use that one, as for
                    // some stupid reason, the fieldcodes can be split across runs.... :/
                    if (code.Text.Trim().IndexOf("INCLUDETEXT", StringComparison.InvariantCultureIgnoreCase) > -1) //this is actually piss-poor, but as a merge field can go across n runs, we simply check for the M and let the other function figure it out..
                    {
                        MergeIncludeText(i, paraRuns, originalDocument);
                    }
                }
            }
        }

        public Run CreateImageRun(WordprocessingDocument sourceDoc, Run sourceRun, WordprocessingDocument target, FooterPart footerPart)
        {
             ImagePart newPart = footerPart.AddImagePart(ImagePartType.Png);

            ImageData shape = sourceRun.Descendants<ImageData>().FirstOrDefault();

            ImagePart p = sourceDoc.MainDocumentPart.GetPartById(shape.RelationshipId) as ImagePart;

            Bitmap image = new Bitmap(p.GetStream()); 

            using (Stream s = p.GetStream())
            {
                s.Position = 0;
                newPart.FeedData(s);
            }

            string partId = footerPart.GetIdOfPart(newPart);

            Drawing newImage = CreateImage(partId);

            return new Run(newImage);
        }

        private Drawing CreateImage(string relationshipId)
        {
            // Define the reference of the image.
            return new Drawing(
                     new DW.Inline(
                         new DW.Extent() { Cx = 990000L, Cy = 792000L },
                         new DW.EffectExtent()
                         {
                             LeftEdge = 0L,
                             TopEdge = 0L,
                             RightEdge = 0L,
                             BottomEdge = 0L
                         },
                         new DW.DocProperties()
                         {
                             Id = (UInt32Value)1U,
                             Name = "Picture 1"
                         },
                         new DW.NonVisualGraphicFrameDrawingProperties(
                             new A.GraphicFrameLocks() { NoChangeAspect = true }),
                         new A.Graphic(
                             new A.GraphicData(
                                 new PIC.Picture(
                                     new PIC.NonVisualPictureProperties(
                                         new PIC.NonVisualDrawingProperties()
                                         {
                                             Id = (UInt32Value)0U,
                                             Name = "New Bitmap Image.jpg"
                                         },
                                         new PIC.NonVisualPictureDrawingProperties()),
                                     new PIC.BlipFill(
                                         new A.Blip(
                                             new A.BlipExtensionList(
                                                 new A.BlipExtension()
                                                 {
                                                     Uri =
                                                       "{28A0092B-C50C-407E-A947-70E740481C1C}"
                                                 })
                                         )
                                         {
                                             Embed = relationshipId,
                                             CompressionState =
                                             A.BlipCompressionValues.Print
                                         },
                                         new A.Stretch(
                                             new A.FillRectangle())),
                                     new PIC.ShapeProperties(
                                         new A.Transform2D(
                                             new A.Offset() { X = 0L, Y = 0L },
                                             new A.Extents() { Cx = 990000L, Cy = 792000L }),
                                         new A.PresetGeometry(
                                             new A.AdjustValueList()
                                         ) { Preset = A.ShapeTypeValues.Rectangle }))
                             ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })
                     )
                     {
                         DistanceFromTop = (UInt32Value)0U,
                         DistanceFromBottom = (UInt32Value)0U,
                         DistanceFromLeft = (UInt32Value)0U,
                         DistanceFromRight = (UInt32Value)0U,
                         EditId = "50D07946"
                     });
        }

        private void ReplaceRunsWithRuns(IEnumerable<Run> fieldRuns, IEnumerable<Run> value, WordprocessingDocument source, WordprocessingDocument target)
        {
            FooterPart f = target.MainDocumentPart.FooterParts.ElementAt(1);

            f.Footer.RemoveAllChildren();

            Paragraph p = new Paragraph();
            //the run has no value to merge into, remove the field.
            if (value != null)
            {
                foreach (var item in value)
                {
                    if (!item.Descendants<Picture>().Any()) //pictures are processed differently - they're an absolute s**t storm to code...
                    {
                        p.Append(item.CloneNode(true));
                    }
                    else
                    {
                        p.Append(CreateImageRun(source, item, target, f));
                    }
                }
            }
            else
            {
            }
            f.Footer.Append(p);
        }

        private void MergeIncludeText(int curRunIdx, List<Run> runs, WordprocessingDocument originalDoc)
        {
            int startRun = GetBeginRun(runs, curRunIdx);

            if (startRun == -1)
            {
                return;
            }

            int endRun = GetEndRun(runs, startRun);

            if (endRun == -1)
            {
                return;
            }

            IEnumerable<Run> fieldRuns = WordMLHelpers.GetRunsBetweenTwoPoints(runs, startRun, endRun);

            IEnumerable<FieldCode> fieldCodes = fieldRuns.SelectMany(x => x.Descendants<FieldCode>());

            string mergeField = string.Concat(fieldCodes.Select(x => x.Text));

            string field = GetIncludeTextFilePath(mergeField);

            MemoryStream ms = LoadDocumentStream(field);

            WordprocessingDocument includeDoc = LoadDocumentFromStream(ms);

            IEnumerable<Run> includedRuns = includeDoc.MainDocumentPart.Document.Descendants<Run>();

            ReplaceRunsWithRuns(fieldRuns, includedRuns, includeDoc, originalDoc);
        }

        private string GetIncludeTextFilePath(string mergeFieldText)
        {
            int quoteStart = mergeFieldText.IndexOf('"') + 1;

            int quoteEnd = mergeFieldText.IndexOf('"', quoteStart);

            return mergeFieldText.Substring(quoteStart, quoteEnd - quoteStart);
        }

        private WordprocessingDocument LoadDocumentFromStream(Stream stream)
        {
            return WordprocessingDocument.Open(stream, true);
        }

#region helpers
        public static int GetBeginRun(IEnumerable<Run> runs, int curIdx)
        {
            for (int i = curIdx; i < runs.Count(); i--)
            {
                if (i == -1)
                {
                    return -1;
                }
                Run run = runs.ElementAt(i);

                if (run.HasChildren && run.ChildElements.OfType<FieldChar>().Count() > 0
                      && (run.ChildElements.OfType<FieldChar>().First().FieldCharType == FieldCharValues.Begin))
                {
                    return i;
                }
            }

            throw new Exception("Begin not found");
        }

        /// <summary>
        /// Get the first End Run in a <see cref="List"/>(<see cref="Run"/>)
        /// </summary>
        /// <param name="runs">The runs.</param>
        /// <param name="curIdx">The cur idx.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">End not found</exception>
        public static int GetEndRun(IEnumerable<Run> runs, int curIdx)
        {
            //runs.FirstOrDefault(x => x.HasChildren && x.Descendants<FieldChar>().Count > 0 && (x.Descendants<FieldChar>().First().FieldCharType & FieldCharValues.End) == FieldCharValues.End);

            for (int i = curIdx; i < runs.Count(); i++)
            {
                if (i == -1)
                {
                    return -1;
                }
                Run run = runs.ElementAt(i);

                if (run.HasChildren && run.Descendants<FieldChar>().Any()
                       && (run.Descendants<FieldChar>().First().FieldCharType == FieldCharValues.End))
                {
                    return i;
                }
            }

            return -1;
        }

        public static MemoryStream LoadDocumentStream(string template)
        {
            using (FileStream fs = File.Open(template, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                // first read document in as stream
                MemoryStream ms = new MemoryStream();

                fs.CopyTo(ms);
                ms.Seek(0, SeekOrigin.Begin);
                return ms;
            }
        }
#endregion


    }

我已经分析了你的word文档。您的word文档存在一些问题:

  1. 如果我尝试在 MS 生产力工具包中打开您的 Word 文档,则会收到错误消息 消息“根元素丢失”。

  2. 如果我将您的文档作为 zip 文件打开(重命名为 mergedfooter.zip),那么 在里面页脚2.xml.rels文件您的图像的关系丢失。 我认为这就是你得到“红框”的原因。

为了进一步分析您的问题,我需要完整的代码(您如何获得FooterPart)?

下面您将找到如何将图像插入 Word 文档页脚的示例。 请注意,下面的示例假设您的 Word 文档已包含页脚并且页脚包含段落元素。

using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open("mydoc.docx", true))
{
  MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart;

  // Search for your footer part here.
  // Just for the sake of simplicity I take the second footer part.
  FooterPart fp = mainPart.FooterParts.ToList()[2];                

  // Create new image part.
  ImagePart ip = fp.AddImagePart(ImagePartType.Jpeg);

  using (FileStream fs = File.Open("mypicture.jpg", FileMode.Open))
  {         
    ip.FeedData(fs);         
  }

  string relationshipId = fp.GetIdOfPart(ip);

  // Create the image element using your function.
  Drawing img = CreateImage(relationshipId);

  Run r = new Run(img);

  Paragraph para = fp.RootElement.Descendants<Paragraph>().FirstOrDefault();

  if(para != null)
  {
    para.Append(r);   
  }      
  else
  {
    Console.WriteLine("paragraph is null...");
  }
}

EDIT:

分析您新提供的文件后:

未保存图像关系的原因是 因为你不Dispose() or Close()你的word文档。

因此,只需添加一条 using 语句:

using (WordprocessingDocument mainDoc = WordprocessingDocument.Open("mydoc.docx", true))
{
  foreach (var item in mainDoc.MainDocumentPart.FooterParts)
  {
    ProcessParaIncludeTextMerge(item, item.Footer.Descendants<Run>(), mainDoc);
    item.Footer.Save();
  }

  mainDoc.MainDocumentPart.Document.Save();           
}

此外在你的ReplaceRunsWithRuns()你必须使用的方法PIC.Picture来参考正确的Picture class:

foreach (var item in value)
{
  if (!item.Descendants<PIC.Picture>().Any())
  {
    p.Append(item.CloneNode(true));
  }
  else
  {
    p.Append(CreateImageRun(source, item, target, f));
  }
}

同样的道理,在你的CreateImageRun()我改变的方法 前三行代码:

ImagePart newPart = footerPart.AddImagePart(ImagePartType.Jpeg);                   
A.Blip shape = sourceRun.Descendants<A.Blip>().FirstOrDefault();
ImagePart p = sourceDoc.MainDocumentPart.GetPartById(shape.Embed.Value) as ImagePart;

通过这些更改,图像出现在mydoc.docx字文档。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

创建 ImagePart 并不将关系保存在 OpenXML 中 的相关文章

  • 将数据集导出到 EXCEL

    我使用以下代码将数据库表中的字段导出到 Excel 中 我想要做的是能够编写一条 SQL 语句从多个表中检索字段并将其导出到 Excel 中 这段代码只允许我导出一张表 另外 如何显示保存提示对话框 示例代码将不胜感激 非常感谢 prote
  • 实体框架 - 循环更新属性

    我正在尝试找到一种方法来循环 EF 对象的属性并更新这些属性的值 更具体地说 我有 50 个字段 其中最多填充 50 个下拉列表 所有 50 个可能都需要填充 也可能不需要填充 为了解决这个问题 我有一个中继器 最多可以创建 50 个 DD
  • 将数组从 C# 编组到 C++ 并返回:PInvokeStackImbalance

    我有一个 C 函数 我想从 C 访问它 问题是我不断收到 PInvokeStackImbalance 异常 但我不知道为什么 当检查异常被关闭时 一切都运行良好并且符合预期 我的 C 函数的签名是 extern C double solve
  • 如何使用Task.WhenAny并实现重试

    我有一个创建多个基于 I O 的任务的解决方案 我正在使用Task WhenAny 来管理这些任务 但通常许多任务会由于网络问题或请求限制等原因而失败 我似乎找不到一个解决方案 使我能够在使用时成功重试失败的任务Task WhenAny 方
  • WPF MVVM将DataTable绑定到DataGrid不显示数据

    我有一个简单的控件 其中包含一个 DataGrid 其中 ItemsSource 绑定到 DataTable 当我填充 DataTable 时 我可以看到 DataGrid 中添加了行 但没有显示任何数据 我没有为此 DataGrid 使用
  • ApiController 操作无法从查询字符串解析数组

    使用 Visual Studio 2012 2 MVC4 Web 应用程序 我有请求发送到我的 ApiController 如下所示 http localhost api keys ids 1 ids 2 ids 3 我的印象是以下方法应该
  • 无法更新 .mdf 数据库,因为该数据库是只读的(Windows 应用程序)

    我使用 C 创建了一个数据库 Windows 应用程序 我的应用程序在 Windows XP 上成功运行 但在 Vista 或 Windows 7 系统上无法正确执行 我的应用程序显示类似以下内容的消息 无法更新 mdf 数据库 因为该数据
  • 在 C 程序中追踪数组越界访问/写入的推荐方法

    考虑用 C 语言编写一些不太明显的算法的实现 例如 让它成为递归快速排序 我在 K N King 的 C 编程 现代方法 第二版 书中找到了它 可以从here http knking com books c2 programs qsort
  • 使用 Thread.Sleep() 时,异步编程如何与线程一起工作?

    假设 前言 在之前的问题中 我们注意到Thread Sleep阻塞线程参见 什么时候使用Task Delay 什么时候使用Thread Sleep https stackoverflow com questions 20082221 whe
  • 使用 C 创建立体声正弦波

    我正在尝试用 C 创建立体声正弦 WAV 并且可能有不同的 可能是空白的 左声道和右声道 使用此函数为每个通道生成一个音调 int16 t create tone float frequency float amplitude float
  • 是否可以用 C# 为 Android 编写应用程序?

    我们都知道Android运行Dalvik VM程序 通常开发人员用 Java 编写程序并将其编译为 Dalvik 字节码 我想知道是否有可能创建一个可以接受 C 代码并将其编译为 Dalvik 字节码的编译器 嗯 这是一种选择 或者您可以在
  • 我应该使用函数还是无状态函子?

    这两段代码做同样的事情 如您所见 它将用于排序函数 哪个更好 我通常写后一种 但我看到一些程序员像以前那样做 struct val lessthan binary function
  • popen2()在c中如何工作?

    我尝试使用管道 叉子和 dup 在我的程序中执行 md5sume 命令 我发现总和代码运行成功 但我无法理解某些代码行 这是我的代码 int infp outfp char buf 128 if popen2 md5sum infp out
  • C++ 克隆惯用语中协变返回类型的用处?

    通常的克隆习惯使用协变返回类型 struct Base virtual Base clone struct Derived public Base Derived clone 我读过一些内容 大意是协变返回类型是 C 后来添加的 较旧的编译
  • 使用经度和纬度查找给定距离内的所有附近客户

    我有一个包含客户经度和纬度的数据库 我有一个搜索表单 用户将在其中输入日志 纬度 距离下拉列表包含 50 英里 100 英里 当用户单击搜索时 我想编写一个 linq 查询从数据库中获取此距离半径内的所有客户 如何使用 C 和 linq 来
  • Parallel.For 和 Break() 误解?

    我正在研究 For 循环中的并行性中断 看完之后this http tipsandtricks runicsoft com CSharp ParallelClass html and this http reedcopsey com 201
  • Yield Return == IEnumerable 和 IEnumerator 吗?

    Is yield return实施的捷径IEnumerable and IEnumerator 是的 您可以在我的书 C in Depth 的第 6 章中找到更多相关信息 幸好第六章是免费提供 http www manning source
  • 为了清楚起见,是否应该在返回类型上使用无用的类型限定符?

    当我们的头文件中有原型时 我们的静态分析工具会抱怨 返回类型上有无用的类型限定符 例如 const int foo 我们这样定义它是因为该函数返回一个永远不会改变的常量 认为 API 看起来更清晰const到位 为了清楚起见 我觉得这类似于
  • 组合框由于某种原因被链接

    我有以下代码来填充 3 个组合框 private void PopulateDDLs SqlConnection connection SqlCommand command SqlDataReader reader DataTable dt
  • 你将如何开始自动化我的工作? - 第2部分

    后续这个问题 https stackoverflow com questions 2796128 how would you start automating my job 在经历了第一波进货 9 小时的复制 粘贴 后 我现在相信我已经满足

随机推荐

  • 如何在 CSS 中用 div 制作尖箭头

    如何在 CSS 中制作尖箭头 不只是一个三角形 而是一个有茎的三角形 就像用弓射出的传统箭一样 我试图通过创建一个 div 容器来做到这一点 其中包含两个容器 左容器和右容器 右侧将包含三角形 左侧将包含三个 div 其中心将被着色以创建主
  • AdMob 在 Android 中需要哪些权限

    On 谷歌的网站他们只提到其中两个
  • 记录 Excel 自动完成的 VBA 代码

    使用VBA编写要在Excel中使用的自定义函数时 如何编写文档注释以便在自动填充公式期间自动显示Excel 例如 当我们开始输入 VLookUp 时 它会显示 Vlookup 作为工具提示的作用 显示输入变量名称 如果我们按功能区中的 插入
  • 静态变量被初始化两次

    考虑我在编译单元中有一个静态变量 它最终出现在static库 libA 然后我有另一个编译单元访问这个变量 最终出现在shared库 libB so 因此 libA 必须链接到 libB 最后我有一个 main 函数也直接从 A 访问静态变
  • iOS 7 - 调整状态栏

    我无法确定如何调整 iOS7 中的状态栏 我的视图控制器有一个tableView 我想要tableView在状态栏下启动 目前 它与状态栏重叠 顶部的标签是headerView in the tableView 我已通过 IB 在视图控制器
  • 矩阵列表中每个元素的平均值

    我有一个包含三个矩阵的列表 a lt matrix runif 100 b lt matrix runif 100 c lt matrix runif 100 mylist lt list a b c 我想获得三个矩阵中每个元素的平均值 我
  • Python3添加日志级别

    我有这段代码 对我来说效果很好 import logging import logging handlers logger None def create logger global logger logger logging getLog
  • jQuery 点击事件在移动浏览器中不起作用

    jQuery 单击事件似乎没有在移动浏览器中触发 HTML如下 ul class menu li a href home HOME a li li class publications PUBLICATIONS amp PROJECTS l
  • C# 的远程 SQL 服务器的正确连接字符串

    我只想知道远程 sql server Express 版本的正确 sql 连接字符串 这就是我得到的 但我遇到了一些问题 SqlConnection cs new SqlConnection Data Source IP Address P
  • 承诺和摩卡:是否在之前完成()?

    我在读关于摩卡承诺测试的一些教程 有一段代码 before function done return Promise resolve save article then function done Why done 调用在then in t
  • 翻译源代码中的注释和区域名称

    有谁知道批处理程序或 VS 2010 插件 脚本可以让我将注释和区域名称从中文翻译成英文 我发现的唯一一个要么处理所有字符串 要么一次只处理一个字符串 我有两个大型 C 项目正在尝试通读 Thanks 使用 PrepTags 准备要翻译的文
  • C# Socket.Receive 消息长度

    我目前正在开发一个 C Socket 服务器 它可以接受来自多个客户端计算机的多个连接 服务器的目标是允许客户端 订阅 和 取消订阅 服务器事件 到目前为止 我已经很好地观察了这里 http msdn microsoft com en us
  • Excel循环遍历行并将单元格值复制到另一个工作表

    我在实现我的预期结果方面面临一些困难macro 意图 我有一个数据列表sheets input column A 具有值的行数会有所不同 因此我创建了一个循环来运行宏 直到活动单元格为空 我的宏从Range A2 并一直向下延伸到 A 列
  • 为什么我们在nodejs中使用导出?

    我是 Nodejs 的新手 就我而言module exports and exports两者都是空对象 module exports可以暴露函数 whileexports可不至于此 一切都可以通过 module exports 来实现 那么
  • 为什么布尔数据类型没有在 C 中实现

    有朋友问了一个问题 为什么没有BooleanC 编程语言中的数据类型 我做了一些搜索和阅读 我在堆栈溢出中得到了一些问题和答案 所有数据类型都应该是可寻址的 但位不能寻址 主流CPU硬件层面的基本数据结构是字节 对这些 CPU 中的位进行操
  • 在 HTML 中对齐小数点

    我有一个表格 其中一列包含十进制数字 我希望以类似于文字处理程序的 小数制表符 功能的方式对齐它们 以便所有点都位于垂直线上 我目前有两种可能的解决方案 但我希望有更好的解决方案 解决方案 1 拆分 HTML 中的数字 例如 td div
  • Javascript 中的预增量

    我刚刚遇到了 Javascript 中关于预增量的 功能 在我使用过的所有其他语言中 它都像我想象的那样 例如 在 C 中 include
  • 向图像添加水印图像

    我想在我的所有图像中添加一个小的淡出水印图像 有没有办法在 c 中做到这一点 您可以使用System Drawing 1 create a bitmap create a empty one or from file Bitmap bmpP
  • 使用 Imagick php 扩展将多页 PDF 转换为 JPG 时出现黑色背景

    使用 Imagick php 扩展将多页 PDF 转换为 JPG 时纠正黑色背景的最佳方法是什么 以下是我的应用程序中使用的代码 imagick new Imagick file imagick gt setResolution 150 1
  • 创建 ImagePart 并不将关系保存在 OpenXML 中

    更新以提供完整的工人阶级示例 以及 2 个示例文档 www sklinar co uk wp content uploads mydoc docx 原始文档包含 INCLUDETEXT 指令以合并到 Footer Docx 中 www sk