コード例 #1
0
 public void Two_Words_With_Tab()
 {
     var reader = new WordReader("hello \tworld");
     Assert.That(reader.NextWord(), Is.EqualTo("hello"));
     Assert.That(reader.NextSpace(), Is.EqualTo(" \t"));
     Assert.That(reader.NextWord(), Is.EqualTo("world"));
     Assert.That(reader.EOF(), Is.True);
 }
コード例 #2
0
        public WordReaderTest()
        {
            _wordDocPath = Path.Combine(Path.GetTempPath(), "renrakuhyou.docx");

            using (Stream file = new FileStream(_wordDocPath, FileMode.Create))
            {
                Assembly.GetExecutingAssembly().GetManifestResourceStream("AutomationKobo.UnitTest.Files.09. 中高理科-前期.docx").CopyTo(file);
            }
            _wordReader = new WordReader(_wordDocPath);
            Assert.IsFalse(_wordReader == null, "_wordReaderのインスタンスが作成されていません。");
            _wordReader.LoadFile();
            Trace.WriteLine("WordReaderTestコンストラクタが実行されました。");
        }
コード例 #3
0
ファイル: OpImage.cs プロジェクト: gleblebedev/Toe.SPIRV
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     SampledImage = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #4
0
 /// <summary>
 /// Read complete instruction from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void Parse(WordReader reader, uint end)
 {
     ParseOperands(reader, end);
     PostParse(reader, end);
 }
コード例 #5
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     Predicate = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #6
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
 }
コード例 #7
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     Execution  = Spv.IdScope.Parse(reader, end - reader.Position);
     NumEvents  = Spv.IdRef.Parse(reader, end - reader.Position);
     EventsList = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #8
0
 public static uint Parse(WordReader reader, uint wordCount)
 {
     return(reader.ReadWord());
 }
コード例 #9
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     Pipe            = Spv.IdRef.Parse(reader, end - reader.Position);
     PacketSize      = Spv.IdRef.Parse(reader, end - reader.Position);
     PacketAlignment = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #10
0
       internal Word(String text, WordReader parent)
           : this(text, 0, parent)
       {
 
       }
コード例 #11
0
 public new static OpenCL_CPPImpl Parse(WordReader reader, uint wordCount)
 {
     return(Instance);
 }
コード例 #12
0
 public new static GLSLImpl Parse(WordReader reader, uint wordCount)
 {
     return(Instance);
 }
コード例 #13
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     Current = Spv.IdRef.Parse(reader, end - reader.Position);
     Next    = Spv.IdRef.Parse(reader, end - reader.Position);
     Delta   = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #14
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     Image         = Spv.IdRef.Parse(reader, end - reader.Position);
     Coordinate    = Spv.IdRef.Parse(reader, end - reader.Position);
     ImageOperands = Spv.ImageOperands.ParseOptional(reader, end - reader.Position);
 }
コード例 #15
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     UnsignedValue = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #16
0
ファイル: StorageClass.cs プロジェクト: gleblebedev/Toe.SPIRV
        public static StorageClass Parse(WordReader reader, uint wordCount)
        {
            var id = (Enumerant)reader.ReadWord();

            switch (id)
            {
            case Enumerant.UniformConstant:
                return(UniformConstantImpl.Parse(reader, wordCount - 1));

            case Enumerant.Input:
                return(InputImpl.Parse(reader, wordCount - 1));

            case Enumerant.Uniform:
                return(UniformImpl.Parse(reader, wordCount - 1));

            case Enumerant.Output:
                return(OutputImpl.Parse(reader, wordCount - 1));

            case Enumerant.Workgroup:
                return(WorkgroupImpl.Parse(reader, wordCount - 1));

            case Enumerant.CrossWorkgroup:
                return(CrossWorkgroupImpl.Parse(reader, wordCount - 1));

            case Enumerant.Private:
                return(PrivateImpl.Parse(reader, wordCount - 1));

            case Enumerant.Function:
                return(FunctionImpl.Parse(reader, wordCount - 1));

            case Enumerant.Generic:
                return(GenericImpl.Parse(reader, wordCount - 1));

            case Enumerant.PushConstant:
                return(PushConstantImpl.Parse(reader, wordCount - 1));

            case Enumerant.AtomicCounter:
                return(AtomicCounterImpl.Parse(reader, wordCount - 1));

            case Enumerant.Image:
                return(ImageImpl.Parse(reader, wordCount - 1));

            case Enumerant.StorageBuffer:
                return(StorageBufferImpl.Parse(reader, wordCount - 1));

            case Enumerant.CallableDataNV:
                return(CallableDataNVImpl.Parse(reader, wordCount - 1));

            //CallableDataKHR has the same id as another value in enum.
            //case Enumerant.CallableDataKHR :
            //    return CallableDataKHR.Parse(reader, wordCount - 1);
            case Enumerant.IncomingCallableDataNV:
                return(IncomingCallableDataNVImpl.Parse(reader, wordCount - 1));

            //IncomingCallableDataKHR has the same id as another value in enum.
            //case Enumerant.IncomingCallableDataKHR :
            //    return IncomingCallableDataKHR.Parse(reader, wordCount - 1);
            case Enumerant.RayPayloadNV:
                return(RayPayloadNVImpl.Parse(reader, wordCount - 1));

            //RayPayloadKHR has the same id as another value in enum.
            //case Enumerant.RayPayloadKHR :
            //    return RayPayloadKHR.Parse(reader, wordCount - 1);
            case Enumerant.HitAttributeNV:
                return(HitAttributeNVImpl.Parse(reader, wordCount - 1));

            //HitAttributeKHR has the same id as another value in enum.
            //case Enumerant.HitAttributeKHR :
            //    return HitAttributeKHR.Parse(reader, wordCount - 1);
            case Enumerant.IncomingRayPayloadNV:
                return(IncomingRayPayloadNVImpl.Parse(reader, wordCount - 1));

            //IncomingRayPayloadKHR has the same id as another value in enum.
            //case Enumerant.IncomingRayPayloadKHR :
            //    return IncomingRayPayloadKHR.Parse(reader, wordCount - 1);
            case Enumerant.ShaderRecordBufferNV:
                return(ShaderRecordBufferNVImpl.Parse(reader, wordCount - 1));

            //ShaderRecordBufferKHR has the same id as another value in enum.
            //case Enumerant.ShaderRecordBufferKHR :
            //    return ShaderRecordBufferKHR.Parse(reader, wordCount - 1);
            case Enumerant.PhysicalStorageBuffer:
                return(PhysicalStorageBufferImpl.Parse(reader, wordCount - 1));

            //PhysicalStorageBufferEXT has the same id as another value in enum.
            //case Enumerant.PhysicalStorageBufferEXT :
            //    return PhysicalStorageBufferEXT.Parse(reader, wordCount - 1);
            default:
                throw new IndexOutOfRangeException("Unknown StorageClass " + id);
            }
        }
コード例 #17
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     StructType = Spv.IdRef.Parse(reader, end - reader.Position);
     Member     = Spv.LiteralInteger.Parse(reader, end - reader.Position);
     Decoration = Spv.Decoration.Parse(reader, end - reader.Position);
 }
コード例 #18
0
ファイル: Form1.cs プロジェクト: yvceng/OfficeMerger
 private void btReplace_Click(object sender, EventArgs e)
 {
     int fileCount = lvFile.Items.Count;
     WordReader reader = new WordReader();
     for (int i = 0; i < fileCount; i++)
     {
         reader.ReplaceOne(lvFile.Items[i].SubItems[2].Text, "代表推荐人选登记表", "代表候选人初步人选登记表");
     }
 }
コード例 #19
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     SamplerAddressingMode = Spv.SamplerAddressingMode.Parse(reader, end - reader.Position);
     Param             = Spv.LiteralInteger.Parse(reader, end - reader.Position);
     SamplerFilterMode = Spv.SamplerFilterMode.Parse(reader, end - reader.Position);
 }
コード例 #20
0
ファイル: StorageClass.cs プロジェクト: gleblebedev/Toe.SPIRV
 public new static UniformConstantImpl Parse(WordReader reader, uint wordCount)
 {
     return(Instance);
 }
コード例 #21
0
        public override void Parse(WordReader reader, uint wordCount)
        {
            var end = reader.Position + wordCount - 1;

            TargetLabel = Spv.IdRef.Parse(reader, end - reader.Position);
        }
コード例 #22
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     RayQuery     = Spv.IdRef.Parse(reader, end - reader.Position);
     Intersection = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #23
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     Event  = Spv.IdRef.Parse(reader, end - reader.Position);
     Status = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #24
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     IndexOffset   = Spv.IdRef.Parse(reader, end - reader.Position);
     PackedIndices = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #25
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     Payload    = Spv.IdRef.Parse(reader, end - reader.Position);
     MajorShape = Spv.IdRef.Parse(reader, end - reader.Position);
     Direction  = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #26
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     Execution = Spv.IdScope.Parse(reader, end - reader.Position);
     Operation = Spv.GroupOperation.Parse(reader, end - reader.Position);
     Value     = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #27
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     SBTIndex       = Spv.IdRef.Parse(reader, end - reader.Position);
     CallableDataId = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #28
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     Operand1 = Spv.IdRef.Parse(reader, end - reader.Position);
     Operand2 = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #29
0
 public void One_Word_With_Dollars()
 {
     var reader = new WordReader("$word$");
     Assert.That(reader.NextWord(), Is.EqualTo("$word$"));
     Assert.That(reader.EOF(), Is.True);
 }
コード例 #30
0
ファイル: OpImage.cs プロジェクト: gleblebedev/Toe.SPIRV
 /// <summary>
 /// Process parsed instruction if required.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 partial void PostParse(WordReader reader, uint end);
コード例 #31
0
ファイル: WordWriter.cs プロジェクト: hiriumi/EasyReporting
 public WordWriter(WordReader reader)
 {
     WordReader = reader;
 }
コード例 #32
0
 public void One_Word()
 {
     var reader = new WordReader("word");
     Assert.That(reader.NextWord(), Is.EqualTo("word"));
     Assert.That(reader.EOF(), Is.True);
 }
コード例 #33
0
ファイル: StorageClass.cs プロジェクト: gleblebedev/Toe.SPIRV
 public new static PhysicalStorageBufferEXTImpl Parse(WordReader reader, uint wordCount)
 {
     return(Instance);
 }
コード例 #34
0
 public static IdRef <TypeInstruction> Parse(WordReader reader, uint wordCount)
 {
     return(IdRef <TypeInstruction> .Parse(reader, wordCount));
 }
コード例 #35
0
        public void Generate(object sender, DoWorkEventArgs args)
        {
            WordReader wordReader = null;
            WordWriter wordWriter = null;
            int progressCount = 0;
            var worker = sender as BackgroundWorker;
            try
            {
                worker.ReportProgress(GetPercentage(progressCount++, MaxDataPoints), "生成プロセスを開始しています…");
                foreach (ExcelToWordMapping.MappingFileRow mappingFileRow in _mappingData.MappingFile)
                {
                    worker.ReportProgress(GetPercentage(progressCount++, MaxDataPoints), String.Format("ワードファイル「{0}」をテンプレートに生成しています…", mappingFileRow.WordTemplateFilePath));

                    #region 一つのファイルに書き出す下準備

                    if (WriteOutToOneFile)
                    {
                        if (mappingFileRow.IsWriteOutFilePathNull())
                        {
                            throw new Exception("WriteOutFilePathが設定されていません");
                        }

                        if (!Directory.Exists(Path.GetDirectoryName(mappingFileRow.WriteOutFilePath)))
                        {
                            throw new Exception(String.Format("ディレクトリ「{0}」が存在しません。",
                                Path.GetDirectoryName(mappingFileRow.WriteOutFilePath)));
                        }

                        if (WriteOutToOneFile && OverwriteExistingFiles)
                        {
                            if (File.Exists(mappingFileRow.WriteOutFilePath))
                            {
                                File.Delete(mappingFileRow.WriteOutFilePath);
                            }
                        }

                        File.Copy(mappingFileRow.WordTemplateFilePath, mappingFileRow.WriteOutFilePath);
                        File.SetAttributes(mappingFileRow.WriteOutFilePath,
                            File.GetAttributes(mappingFileRow.WriteOutFilePath) &
                            ~FileAttributes.ReadOnly);

                        wordReader = new WordReader(mappingFileRow.WriteOutFilePath);
                        wordReader.LoadFile();

                        if (!String.IsNullOrEmpty(ProtectPassword))
                        {
                            wordWriter = new WordWriter(wordReader);
                            wordWriter.UnprotectDocument(ProtectPassword);
                        }
                    } // if (WriteOutToOneFile)
                    else
                    {
                        OutputDirPath = mappingFileRow.OutputDirPath;

                        if (String.IsNullOrEmpty(OutputDirPath))
                        {
                            throw new Exception("OutputDirPathのプロパティをセットしてください。");
                        }

                        if (!Directory.Exists(OutputDirPath))
                        {
                            throw new IOException(String.Format("ディレクトリ{0}は存在しません。", OutputDirPath));
                        }
                    }

                    #endregion

                    if (!mappingFileRow.DoIt)
                        continue;

                    DataRow[] refSheetRows = mappingFileRow.GetChildRows("MappingHistory_RefSheet");
                    var generatedFiles = new Dictionary<string, string>();
                    var generatedPages = new Dictionary<string, Range>();

                    foreach (ExcelToWordMapping.RefSheetRow refSheetRow in refSheetRows)
                    {
                        worker.ReportProgress(GetPercentage(progressCount++, MaxDataPoints), String.Format("シート「{0}」を参照して氏名を抽出しています…", refSheetRow.RefSheetName));

                        if (StartingRow < refSheetRow.DataStartingRow)
                        {
                            StartingRow = refSheetRow.DataStartingRow;
                        }

                        Dictionary<int, string> identifiers = _excelReader.GetIdNames(refSheetRow.RefSheetName, StartingRow, EndingRow);
                        Dictionary<string, int> dataIdColumnList = _excelReader.GetColumnIdList(refSheetRow.ColumnIdRow, refSheetRow.RefSheetName);

                        int count = 1;
                        foreach (var identifier in identifiers)
                        {
                            worker.ReportProgress(GetPercentage(progressCount++, MaxDataPoints), String.Format("「{0}」に対してワードファイルを生成中…", refSheetRow.RefSheetName));
                            if (WriteOutToOneFile)
                            {
                                #region 一つのファイルに書き出すプロセス

                                if (wordReader == null)
                                {
                                    wordReader = new WordReader(mappingFileRow.WriteOutFilePath);
                                    wordReader.LoadFile();
                                }

                                if (wordWriter == null)
                                {
                                    wordWriter = new WordWriter(wordReader);
                                }

                                Range targetPage;
                                if (!generatedPages.ContainsKey(identifier.Value))
                                {
                                    targetPage = wordWriter.DuplicateFirstPage();
                                    generatedPages.Add(identifier.Value, targetPage);
                                }
                                else
                                {
                                    targetPage = generatedPages[identifier.Value];
                                }

                                // ここから実際にマッピングのデータを利用してエクセルからワードにデータを入力する。
                                Dictionary<int, Pair> identifierValues = _excelReader.GetValues(refSheetRow.RefSheetName, dataIdColumnList.Values.ToList(), identifier.Value);
                                foreach (ExcelToWordMapping.MappingRow mappingRow in refSheetRow.GetMappingRows())
                                {
                                    ContentControl targetContentControl = GetContentControl(targetPage.ContentControls, mappingRow.WordContentControlTitle);
                                    if (targetContentControl == null)
                                    {
                                        continue;
                                    }

                                    object value = null;
                                    string text = String.Empty;
                                    if (dataIdColumnList.ContainsKey(mappingRow.ExcelColumnIdName))
                                    {
                                        value = identifierValues[dataIdColumnList[mappingRow.ExcelColumnIdName]].Value;
                                        text = ConvertToZenkaku
                                            ? Strings.StrConv(
                                                identifierValues[dataIdColumnList[mappingRow.ExcelColumnIdName]]
                                                    .Text, VbStrConv.Wide, 1041)
                                            : identifierValues[dataIdColumnList[mappingRow.ExcelColumnIdName]].Text;
                                    }

                                    worker.ReportProgress(GetPercentage(progressCount++, MaxDataPoints), String.Format("{0}の{1}に値「{2}」を書き入れます。", mappingFileRow.WriteOutFilePath, mappingRow.WordContentControlTitle, text));
                                    SetContentControlValue(targetContentControl, text);
                                    if ((!mappingRow.IsScriptNull()) && !String.IsNullOrEmpty(mappingRow.Script))
                                    {
                                        try
                                        {
                                            var scriptExecuter = new WordScriptExecuter("C#", mappingRow.Script, _namespaces);
                                            scriptExecuter.ContentControl = targetContentControl;
                                            scriptExecuter.ActualValue = value;
                                            scriptExecuter.ExecuteScript();
                                        }
                                        catch (Exception scriptExp)
                                        {
                                            string errMsg = String.Format("{0}のスクリプトでエラーが発生しました。\r\n{1}", mappingRow.WordContentControlTitle, scriptExp.Message);
                                            throw new Exception(errMsg, scriptExp);
                                        }
                                    }
                                } // foreach (ExcelToWordMapping.MappingRow mappingRow in refSheetRow.GetMappingRows())

                                // ここから固定値の挿入へ。
                                DataRow[] literalValueMappingRows = _mappingData.Mapping.Select("LiteralValue IS NOT NULL");
                                if (literalValueMappingRows.Length > 0)
                                {
                                    foreach (ExcelToWordMapping.MappingRow literalValueMappingRow in literalValueMappingRows)
                                    {
                                        ContentControl targetContentControl = GetContentControl(targetPage.ContentControls, literalValueMappingRow.WordContentControlTitle);
                                        if (targetContentControl == null)
                                        {
                                            continue;
                                        }

                                        string text = literalValueMappingRow.LiteralValue;
                                        worker.ReportProgress(GetPercentage(progressCount++, MaxDataPoints), String.Format("{0}の{1}に値「{2}」を書き入れます。", mappingFileRow.WriteOutFilePath, literalValueMappingRow.WordContentControlTitle, text));
                                        SetContentControlValue(targetContentControl, text);
                                        if ((!literalValueMappingRow.IsScriptNull()) &&
                                            !String.IsNullOrEmpty(literalValueMappingRow.Script))
                                        {
                                            try
                                            {
                                                var scriptExecuter = new WordScriptExecuter("C#", literalValueMappingRow.Script, _namespaces);
                                                scriptExecuter.ContentControl = targetContentControl;
                                                scriptExecuter.ActualValue = text;
                                                scriptExecuter.ExecuteScript();
                                            }
                                            catch (Exception scriptExp)
                                            {
                                                string errMsg = String.Format("{0}のスクリプトでエラーが発生しました。\r\n{1}", literalValueMappingRow.WordContentControlTitle, scriptExp.Message);
                                                throw new Exception(errMsg, scriptExp);
                                            }
                                        }
                                    }
                                }

                                #endregion
                            }
                            else // if (WriteOutToOneFile)
                            {
                                #region 生成のターゲットになるワードファイルを決める。

                                string targetWordFile = String.Empty;
                                if (generatedFiles.ContainsKey(identifier.Value))
                                {
                                    targetWordFile = generatedFiles[identifier.Value];
                                }
                                else
                                {
                                    string fileName = Core.IO.Path.CleanFileName(identifier.Value);
                                    if (ConvertToZenkaku)
                                    {
                                        fileName = Strings.StrConv(fileName, VbStrConv.Wide, 1041);
                                    }

                                    if (AssignSequentialNumber)
                                    {
                                        string renban = count.ToString(CultureInfo.InvariantCulture).Length == 1
                                            ? "0" + count.ToString(CultureInfo.InvariantCulture)
                                            : count.ToString(CultureInfo.InvariantCulture);

                                        targetWordFile = Path.Combine(mappingFileRow.OutputDirPath, renban + ". " + fileName + Path.GetExtension(mappingFileRow.WordTemplateFilePath));
                                    }
                                    else if (AssignRowIndexNumber)
                                    {
                                        targetWordFile = Path.Combine(mappingFileRow.OutputDirPath, identifier.Key + ". " + fileName + Path.GetExtension(mappingFileRow.WordTemplateFilePath));
                                    }
                                    else
                                    {
                                        targetWordFile = Path.Combine(mappingFileRow.OutputDirPath,
                                            fileName +
                                            Path.GetExtension(
                                                mappingFileRow.WordTemplateFilePath));
                                    }

                                    if (File.Exists(targetWordFile) && (OverwriteExistingFiles))
                                    {
                                        File.Delete(targetWordFile);
                                    }

                                    File.Copy(mappingFileRow.WordTemplateFilePath, targetWordFile);
                                    File.SetAttributes(targetWordFile,
                                        File.GetAttributes(targetWordFile) & ~FileAttributes.ReadOnly);
                                    generatedFiles.Add(identifier.Value, targetWordFile);

                                    count++;
                                }

                                #endregion

                                #region 別々のファイルに書き出すプロセス

                                try
                                {
                                    //ここまででターゲットのワードファイルが決まったので、読み込んで値を入れていく。
                                    wordReader = new WordReader(targetWordFile);
                                    wordReader.LoadFile();

                                    // ここから実際にマッピングのデータを利用してエクセルからワードにデータを入力する。
                                    Dictionary<int, Pair> identifierValues = _excelReader.GetValues(refSheetRow.RefSheetName,
                                        dataIdColumnList.Values.ToList(), identifier.Value);

                                    foreach (ExcelToWordMapping.MappingRow mappingRow in refSheetRow.GetMappingRows())
                                    {
                                        ContentControl targetContentControl =
                                            wordReader.GetContentControl(mappingRow.WordContentControlTitle);
                                        if (targetContentControl == null)
                                        {
                                            continue;
                                        }

                                        object value = null;
                                        string text = String.Empty;
                                        if (dataIdColumnList.ContainsKey(mappingRow.ExcelColumnIdName))
                                        {
                                            value =
                                                identifierValues[dataIdColumnList[mappingRow.ExcelColumnIdName]].Value;
                                            text = ConvertToZenkaku
                                                ? Strings.StrConv(
                                                    identifierValues[dataIdColumnList[mappingRow.ExcelColumnIdName]]
                                                        .Text, VbStrConv.Wide, 1041)
                                                : identifierValues[dataIdColumnList[mappingRow.ExcelColumnIdName]].Text;
                                        }

                                        worker.ReportProgress(GetPercentage(progressCount++, MaxDataPoints),
                                            String.Format("{0}の{1}に値「{2}」を書き入れます。", targetWordFile,
                                                mappingRow.WordContentControlTitle, text));
                                        SetContentControlValue(targetContentControl, text);

                                        if ((!mappingRow.IsScriptNull()) && !String.IsNullOrEmpty(mappingRow.Script))
                                        {
                                            try
                                            {
                                                var scriptExecuter = new WordScriptExecuter("C#", mappingRow.Script, _namespaces);
                                                scriptExecuter.ContentControl = targetContentControl;
                                                scriptExecuter.ActualValue = value;
                                                scriptExecuter.ExecuteScript();
                                            }
                                            catch (Exception scriptExp)
                                            {
                                                string errMsg = String.Format("{0}のスクリプトでエラーが発生しました。\r\n{1}", mappingRow.WordContentControlTitle, scriptExp.Message);
                                                throw new Exception(errMsg, scriptExp);
                                            }
                                        }
                                    }
                                    // foreach (ExcelToWordMapping.MappingRow mappingRow in refSheetRow.GetMappingRows())

                                    // ここから固定値の挿入へ。
                                    DataRow[] literalValueMappingRows = _mappingData.Mapping.Select("LiteralValue IS NOT NULL");
                                    if (literalValueMappingRows.Length > 0)
                                    {
                                        foreach (
                                            ExcelToWordMapping.MappingRow literalValueMappingRow in literalValueMappingRows)
                                        {
                                            ContentControl targetContentControl = wordReader.GetContentControl(literalValueMappingRow.WordContentControlTitle);
                                            if (targetContentControl == null)
                                            {
                                                continue;
                                            }

                                            string text = literalValueMappingRow.LiteralValue;
                                            worker.ReportProgress(GetPercentage(progressCount++, MaxDataPoints), String.Format("{0}の{1}に値「{2}」を書き入れます。", targetWordFile, literalValueMappingRow.WordContentControlTitle, text));
                                            SetContentControlValue(targetContentControl, text);
                                        }
                                    }

                                    var writer = new WordWriter(wordReader);
                                    writer.SaveFilePath = targetWordFile;
                                    writer.Save();
                                    if (CancelRequested)
                                    {
                                        args.Cancel = true;
                                        return;
                                    }
                                }
                                finally
                                {
                                    if (wordReader != null)
                                        wordReader.Dispose();
                                }

                                #endregion
                            }
                        }
                    }

                    if (WriteOutToOneFile)
                    {
                        if (wordWriter != null)
                        {
                            wordWriter.SaveFilePath = mappingFileRow.WriteOutFilePath;
                            wordWriter.Save();
                        }

                        if (wordReader != null)
                            wordReader.Dispose();

                        if (CancelRequested)
                        {
                            args.Cancel = true;
                            worker.ReportProgress(100, "生成プロセスがキャンセルされました。");
                        }
                    }
                }

                var res = new {Text = "生成プロセスが終了しました。", Result = true};
                args.Result = res;
                //worker.ReportProgress(100, "生成プロセスが終了しました。");
                //args.Result = true;
            }
            catch (Exception exp)
            {
                var res = new {Text = exp.ToString(), Result = false};
                args.Result = res;
            }
            finally
            {
                if (wordReader != null)
                    wordReader.Dispose();
            }
        }
コード例 #36
0
ファイル: Form1.cs プロジェクト: yvceng/OfficeMerger
 //将所有内容读取保存到myarray
 private void btReadWord_Click(object sender, EventArgs e)
 {
     int fileCount = lvFile.Items.Count;
     WordReader reader = new WordReader();
     reader.ResetData();
     for (int i = 0; i < fileCount; i++)
     {
         reader.ReadOne(lvFile.Items[i].SubItems[2].Text);
         reader.dataArray[i, reader.colCount] = lvFile.Items[i].SubItems[0].Text;
     }
     myArray = reader.dataArray;
     MessageBox.Show("读取完毕");
 }
コード例 #37
0
 /// <summary>
 /// Read instruction operands from the bytecode source.
 /// </summary>
 /// <param name="reader">Bytecode source.</param>
 /// <param name="end">Index of a next word right after this instruction.</param>
 public override void ParseOperands(WordReader reader, uint end)
 {
     StorageClass = Spv.StorageClass.Parse(reader, end - reader.Position);
     Type         = Spv.IdRef.Parse(reader, end - reader.Position);
 }
コード例 #38
0
        public DataValidationResult ValidateData(out List<string> errors)
        {
            errors = new List<string>();
            var dataValidationResult = DataValidationResult.Good;

            if (_data.MappingFile.Count == 0)
            {
                errors.Add("マッピングデータが空です。");
                dataValidationResult = DataValidationResult.NotGood;
            }
            else
            {
                foreach (ExcelToWordMapping.MappingFileRow mappingFileRow in _data.MappingFile)
                {
                    List<ContentControl> contentsControlList = null;

                    if (!File.Exists(mappingFileRow.WordTemplateFilePath))
                    {
                        errors.Add(String.Format("MappingFile内のデータID「{0}」においてワードの雛形「{1}」が存在しません。", mappingFileRow.MappingFileID, mappingFileRow.WordTemplateFilePath));
                        dataValidationResult = DataValidationResult.NotGood;
                    }
                    else
                    {
                        var wordReader = new WordReader(mappingFileRow.WordTemplateFilePath);
                        wordReader.LoadFile();
                        contentsControlList = wordReader.GetContentControlTitles();
                        wordReader.Dispose();
                    }

                    //if (!Directory.Exists(mappingFileRow.OutputDirPath))
                    //{
                    //    errors.Add(String.Format("MappingFile内のデータID「{0}」のOutputDirPathの値が「{1}」で存在しません。", mappingFileRow.MappingFileID, mappingFileRow.OutputDirPath));
                    //    dataValidationResult = DataValidationResult.NotGood;
                    //}

                    ExcelToWordMapping.RefSheetRow[] refSheetRows = mappingFileRow.GetRefSheetRows();
                    foreach (ExcelToWordMapping.RefSheetRow refSheetRow in refSheetRows)
                    {
                        if (!SheetExists(refSheetRow.RefSheetName))
                        {
                            errors.Add(String.Format("RefSheet内のデータID「{0}」においてシート名「{1}」がエクセルブック内に存在しません。", refSheetRow.RefSheetID, refSheetRow.RefSheetName));
                            dataValidationResult = DataValidationResult.NotGood;
                            continue;
                        }

                        Dictionary<string, int> columnIdList = _excelReader.GetColumnIdList(refSheetRow.ColumnIdRow, refSheetRow.RefSheetName);

                        ExcelToWordMapping.MappingRow[] mappingRows = refSheetRow.GetMappingRows();
                        foreach (ExcelToWordMapping.MappingRow mappingRow in mappingRows)
                        {
                            if (!columnIdList.ContainsKey(mappingRow.ExcelColumnIdName))
                            {
                                errors.Add(String.Format("現在開かれているExcelブック「{0}」のシート「{1}」には列名「{2}」が存在しません。", _excelReader.FilePath, refSheetRow.RefSheetName, mappingRow.ExcelColumnIdName));
                                dataValidationResult = DataValidationResult.NotGood;
                            }

                            bool controlExists = false;
                            foreach (ContentControl c in contentsControlList)
                            {
                                if (mappingRow.WordContentControlTitle == c.Title)
                                {
                                    controlExists = true;
                                }
                            }

                            if ((contentsControlList != null) && (!controlExists))
                            {
                                errors.Add(String.Format("雛形のワードファイル「{0}」にはコンテンツコントロール「{1}」が存在しません。", mappingFileRow.WordTemplateFilePath, mappingRow.WordContentControlTitle));
                                dataValidationResult = DataValidationResult.Ok;
                            }
                        }
                    }
                }
            }

            return dataValidationResult;
        }
コード例 #39
0
 public new static RayQueryCommittedIntersectionGeneratedKHRImpl Parse(WordReader reader, uint wordCount)
 {
     return(Instance);
 }
コード例 #40
0
 internal Word(String text, int start, WordReader parent)
     :this(text, start)
 {
     Parent = parent;
     Parent.OnQuery += new Semantics.Query(Query);
 }
コード例 #41
0
ファイル: StorageClass.cs プロジェクト: gleblebedev/Toe.SPIRV
 public new static ShaderRecordBufferKHRImpl Parse(WordReader reader, uint wordCount)
 {
     return(Instance);
 }