SVN r938
SVN-Revision: r938
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Spire.Doc;
|
||||
using Spire.Doc.Collections;
|
||||
using Spire.Doc.Documents;
|
||||
using Spire.Doc.Fields;
|
||||
using Spire.Doc.Formatting;
|
||||
@@ -206,6 +207,7 @@ namespace Lskj.AutoCreatWord
|
||||
}
|
||||
if (moduleIdStr.Length == 8 && moduleIdStr.StartsWith("XMBG", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
document.ReplaceTextRange(moduleIdStr, $"XMBG_{order}_{index}", false, true);
|
||||
document.Replace(moduleIdStr, $"XMBG_{order}_{index}", false, true);
|
||||
}
|
||||
}
|
||||
@@ -228,22 +230,26 @@ namespace Lskj.AutoCreatWord
|
||||
{
|
||||
DataRow dataRow = dataTable.Rows.Count > 0 ? dataTable.Rows[0] : null;
|
||||
string speciesItem = "!{" + data + "." + dataColumn + "}";
|
||||
bool speciesContains = document.Replace(speciesItem, speciesItem, false, true) > 0;
|
||||
if (speciesContains)
|
||||
TextSelection[] speciesContains = document.FindAllString(speciesItem, false, true);
|
||||
//bool speciesContains = document.Replace(speciesItem, speciesItem, false, true) > 0;
|
||||
if (speciesContains?.Length > 0)
|
||||
{
|
||||
if ((dataRow[dataColumn] + "").Equals("/"))
|
||||
{
|
||||
document.ReplaceTextRange(speciesItem, "!/", false, true);
|
||||
document.Replace(speciesItem, "!/", false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
document.ReplaceTextRange(speciesItem, dataRow[dataColumn] + "", false, true);
|
||||
document.Replace(speciesItem, dataRow[dataColumn] + "", false, true);
|
||||
}
|
||||
}
|
||||
string item = "{" + data + "." + dataColumn + "}";
|
||||
// 替换文档中的占位符
|
||||
bool contains = document.Replace(item, item, false, true) > 0;
|
||||
if (contains)//基础数据直接替换
|
||||
TextSelection[] contains = document.FindAllString(item, false, true);
|
||||
//bool contains = document.Replace(item, item, false, true) > 0;
|
||||
if (contains?.Length > 0)//基础数据直接替换
|
||||
{
|
||||
if (dataRow != null)
|
||||
{
|
||||
@@ -344,11 +350,14 @@ namespace Lskj.AutoCreatWord
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
document.ReplaceTextRange(item, dataRow[dataColumn] + "", false, true);
|
||||
document.Replace(item, dataRow[dataColumn] + "", false, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
document.ReplaceTextRange(item, "", false, true);
|
||||
document.Replace(item, "", false, true);
|
||||
}
|
||||
}
|
||||
@@ -371,22 +380,26 @@ namespace Lskj.AutoCreatWord
|
||||
foreach (DataColumn dataColumn in distinctTable.Columns)
|
||||
{
|
||||
string speciesItem = "!{" + pargTag + "." + dataColumn + "}";
|
||||
bool speciesContains = document.Replace(speciesItem, speciesItem, false, true) > 0;
|
||||
if (speciesContains)
|
||||
//bool speciesContains = document.Replace(speciesItem, speciesItem, false, true) > 0;
|
||||
TextSelection[] speciesContains = document.FindAllString(speciesItem, false, true);
|
||||
if (speciesContains?.Length > 0)
|
||||
{
|
||||
if ((dataRow[dataColumn] + "").Equals("/"))
|
||||
{
|
||||
document.ReplaceTextRange(speciesItem, "!/", false, true);
|
||||
document.Replace(speciesItem, "!/", false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
document.ReplaceTextRange(speciesItem, dataRow[dataColumn] + "", false, true);
|
||||
document.Replace(speciesItem, dataRow[dataColumn] + "", false, true);
|
||||
}
|
||||
}
|
||||
string item = "{" + pargTag + "." + dataColumn + "}";
|
||||
// 替换文档中的占位符
|
||||
bool contains = document.Replace(item, item, false, true) > 0;
|
||||
if (contains)//基础数据直接替换
|
||||
//bool contains = document.Replace(item, item, false, true) > 0;
|
||||
TextSelection[] contains = document.FindAllString(item, false, true);
|
||||
if (contains?.Length > 0)//基础数据直接替换
|
||||
{
|
||||
if (dataColumn.ColumnName.Contains("img_"))//单行替换图片
|
||||
{
|
||||
@@ -468,6 +481,7 @@ namespace Lskj.AutoCreatWord
|
||||
}
|
||||
else
|
||||
{
|
||||
document.ReplaceTextRange(item, dataRow[dataColumn] + "", false, true);
|
||||
document.Replace(item, dataRow[dataColumn] + "", false, true);
|
||||
}
|
||||
}
|
||||
@@ -900,9 +914,10 @@ namespace Lskj.AutoCreatWord
|
||||
foreach (DataColumn dataColumn in sourceTable.Columns)
|
||||
{
|
||||
string lastColumn = "{L#Data" + sourceGridTarGet.number + "." + dataColumn + "}";
|
||||
if (document.Replace(lastColumn, lastColumn, false, true) > 0)
|
||||
if (document.FindAllString(lastColumn, false, true)?.Length > 0)//document.Replace(lastColumn, lastColumn, false, true) > 0
|
||||
{
|
||||
string value = sourceTable.Rows.Count > 0 ? sourceTable.Rows[sourceTable.Rows.Count - 1][dataColumn] + "" : "";
|
||||
document.ReplaceTextRange(lastColumn, value, false, true);
|
||||
document.Replace(lastColumn, value, false, true);
|
||||
break;
|
||||
}
|
||||
@@ -1343,9 +1358,10 @@ namespace Lskj.AutoCreatWord
|
||||
foreach (DataColumn dataColumn in sourceTable.Columns)
|
||||
{
|
||||
string lastColumn = "{L#" + sourceGridTarGet.number + "." + dataColumn + "}";
|
||||
if (document.Replace(lastColumn, lastColumn, false, true) > 0)
|
||||
if (document.FindAllString(lastColumn, false, true)?.Length > 0)//document.Replace(lastColumn, lastColumn, false, true) > 0
|
||||
{
|
||||
string value = sourceTable.Rows.Count > 0 ? sourceTable.Rows[sourceTable.Rows.Count - 1][dataColumn] + "" : "";
|
||||
document.ReplaceTextRange(lastColumn, value, false, true);
|
||||
document.Replace(lastColumn, value, false, true);
|
||||
break;
|
||||
}
|
||||
@@ -1618,4 +1634,28 @@ namespace Lskj.AutoCreatWord
|
||||
private static Image Base64ToImage(string base64String)
|
||||
{
|
||||
Image image = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(base64String))
|
||||
{
|
||||
string pattern = @".*;base64,";
|
||||
base64String = Regex.Replace(base64String, pattern, "");
|
||||
byte[] imageBytes = Convert.FromBase64String(base64String);
|
||||
using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
|
||||
{
|
||||
ms.Write(imageBytes, 0, imageBytes.Length);
|
||||
image = Image.FromStream(ms, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return image;
|
||||
}
|
||||
/// <summary>
|
||||
/// 替换值
|
||||
/// </summary>
|
||||
/// <param name="objects"></param>
|
||||
/// <param name="searchText"></param>
|
||||
|
||||
Reference in New Issue
Block a user