Commit 449a00af authored by 潘栩锋's avatar 潘栩锋 🚴

添加多国语言excel文本

parent 063b1c95

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34916.146
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfApp1", "WpfApp1\WpfApp1.csproj", "{03F35DC4-998E-439F-A5E0-A2BB86B0B43D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{03F35DC4-998E-439F-A5E0-A2BB86B0B43D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03F35DC4-998E-439F-A5E0-A2BB86B0B43D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03F35DC4-998E-439F-A5E0-A2BB86B0B43D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03F35DC4-998E-439F-A5E0-A2BB86B0B43D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CC20E088-610A-43CB-8D17-C49589C6CEA4}
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
\ No newline at end of file
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace WpfApp1
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
}
}
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
<Costura />
</Weavers>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="TriggerDependentProperties" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the Dependent properties feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EnableIsChangedProperty" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the IsChanged property feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressWarnings" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings from this weaver.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="SuppressOnPropertyNameChangedWarning" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to turn off build warnings about mismatched On_PropertyName_Changed methods.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeRuntimeReferences" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if runtime assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseRuntimeReferencePaths" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls whether the runtime assemblies are embedded with their full path or only with their assembly name.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCleanup" type="xs:boolean">
<xs:annotation>
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
\ No newline at end of file
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="3"/>
<Setter Property="Padding" Value="20,5"/>
</Style>
</Window.Resources>
<Grid>
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="3">
<Button Content="生成XLSX" Click="btnCreateXlsxClick"/>
<Button Content="XLSX转资源文件"/>
</StackPanel>
</StackPanel>
</Grid>
</Window>
using Microsoft.Win32;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
//using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Drawing;
namespace WpfApp1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
List<XlsxInfo> xlsxInfos;
string rootPath = @"D:\研发\fly\项目\xxxxxxxx_测厚仪程序\window\20.项目集.吹膜测厚.中山和美\hemei_dev8";
public MainWindow()
{
InitializeComponent();
Init();
ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
}
void Init()
{
//全部项目
xlsxInfos = new List<XlsxInfo>
{
new XlsxInfo()
{
FileName = "风环",
Projects = new List<string>
{
@"Project.FLY.FeedbackRenZiJia\FLY.FeedbackRenZiJia",
@"Project.FLY.FeedbackRenZiJia\FLY.FeedbackRenZiJia.UI.Client",
@"Project.FLY.FeedbackRenZiJia\FLY.FeedbackRenZiJia.UI.Server",
}
},
new XlsxInfo()
{
FileName = "IBC",
Projects = new List<string>
{
@"Project.FLY.IBC\FLY.IBC",
@"Project.FLY.IBC\FLY.IBC.UI.Client",
@"Project.FLY.IBC\FLY.IBC.UI.Server"
}
},
new XlsxInfo()
{
FileName = "测厚追边",
Projects = new List<string>
{
@"Project.FLY.Thick.Blowing\FLY.Thick.Blowing.UI",
@"Project.FLY.Thick.Blowing\FLY.Thick.Blowing.UI.Fix.Client",
@"Project.FLY.Thick.Blowing\FLY.Thick.Blowing.UI.Fix.Server"
}
},
new XlsxInfo()
{
FileName = "测厚平扫",
Projects = new List<string>
{
@"Project.FLY.Thick.BlowingScan\FLY.Thick.BlowingScan.UI",
@"Project.FLY.Thick.BlowingScan\FLY.Thick.BlowingScan.UI.Client",
@"Project.FLY.Thick.BlowingScan\FLY.Thick.BlowingScan.UI.Server"
}
},
new XlsxInfo()
{
FileName = "称重",
Projects = new List<string>
{
@"Project.FLY.Weight\FLY.Weight",
@"Project.FLY.Weight\FLY.Weight.UI.Client",
@"Project.FLY.Weight\FLY.Weight.UI.Server"
}
},
new XlsxInfo()
{
FileName = "收卷",
Projects = new List<string>
{
@"Project.FLY.Winder\FLY.Winder",
@"Project.FLY.Winder\FLY.Winder.UI.Client",
@"Project.FLY.Winder\FLY.Winder.UI.Server"
}
},
new XlsxInfo()
{
FileName = "测厚",
Projects = new List<string>
{
@"thick_public\Project.FLY.Thick.Base\FLY.Thick.Base",
@"thick_public\Project.FLY.Thick.Base\FLY.Thick.Base.UI"
}
}
};
//枚举每个项目的 StringResource.XXX.xaml
Regex regex = new Regex(@"StringResource\.(.+)\.xaml");
//D:\研发\fly\项目\xxxxxxxx_测厚仪程序\window\20.项目集.吹膜测厚.中山和美\hemei_dev8\Project.FLY.FeedbackRenZiJia\FLY.FeedbackRenZiJia\Themes\StringResources\StringResource.ERRNO.xaml
for (int i = 0; i < xlsxInfos.Count(); i++)
{
var xlsxInfo = xlsxInfos[i];
Dictionary<string, string> xamlList = new Dictionary<string, string>();
for (int j = 0; j < xlsxInfo.Projects.Count(); j++)
{
var project = xlsxInfo.Projects[j];
string relativePath = System.IO.Path.Combine(project, @"Themes\StringResources");
string dirPath = System.IO.Path.Combine(rootPath, relativePath);
DirectoryInfo dir = new DirectoryInfo(dirPath);
var files = dir.GetFiles("StringResource.*.xaml");
if (files.Count() == 0)
{
throw new Exception($"不能在 {relativePath} 找到 StringResource.*.xaml");
}
foreach (var file in files)
{
//分解
//file.Name
var match = regex.Match(file.Name);
if (!match.Success)
throw new Exception($"在 {relativePath} 找到 {file.Name} 不符合 StringResource.*.xaml");
string key = match.Groups[1].Value;
bool canAdd = true;
if (xamlList.ContainsKey(key))
{
canAdd = false;
//已经包含这个key 加后序 01~99
for (int k = 0; k < 100; k++)
{
string key1 = key + k.ToString("00");
if (!xamlList.ContainsKey(key1))
{
//加后序成功
key = key1;
canAdd = true;
break;
}
}
}
if (!canAdd)
{
throw new Exception($"在 {relativePath} 找到 {file.Name} 后序加到99 都无法唯一");
}
string fileRelativePath = System.IO.Path.Combine(relativePath, file.Name);
xamlList.Add(key, fileRelativePath);
}
}
foreach (var kv in xamlList) {
xlsxInfo.Xamls.Add(new XamlPathInfo() { name = kv.Key, path = kv.Value });
}
}
}
class XlsxInfo
{
public string FileName;
public List<XamlPathInfo> Xamls = new List<XamlPathInfo>();
public List<string> Projects = new List<string>();
}
private void btnCreateXlsxClick(object sender, RoutedEventArgs e)
{
string strDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
//导出一个文件夹
System.Windows.Forms.FolderBrowserDialog open = new System.Windows.Forms.FolderBrowserDialog();
open.SelectedPath = strDesktopPath;
if (open.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
string dirPath = System.IO.Path.Combine(open.SelectedPath, $"hemei_多国语言_{DateTime.Now:yyyyMMddHHmmss}");
//创建文件夹
System.IO.Directory.CreateDirectory(dirPath);
//加载资源文件
for (int i = 0; i < xlsxInfos.Count(); i++)
{
//创建XLSX
var xlsxInfo = xlsxInfos[i];
string filePath = System.IO.Path.Combine(dirPath, xlsxInfo.FileName + ".xlsx");
using (ExcelPackage p = new ExcelPackage(new FileInfo(filePath)))
{
Console.WriteLine($"{i:00}/{xlsxInfos.Count()}.{xlsxInfo.FileName} 写入PATH表");
SaveToXlsxSheetPath(p, xlsxInfo.Xamls);
Console.WriteLine($"{i:00}/{xlsxInfos.Count()}.{xlsxInfo.FileName} 写入StringResources表");
SaveToXlsxStringResources(p, xlsxInfo.Xamls);
//for (int j = 0; j < xlsxInfo.Xamls.Count(); j++)
//{
// var xamlInfo = xlsxInfo.Xamls[j];
// SaveToXlsxStringResources(p, xamlInfo);
//}
p.Save();
}
}
Console.WriteLine($"完成");
MessageBox.Show("完成");
}
void SaveToXlsxSheetPath(ExcelPackage p, List<XamlPathInfo> xamls)
{
var columnInfos = new List<ColumnInfo<XamlPathInfo>>
{
new ColumnInfo<XamlPathInfo>("name", typeof(string), null, (s)=>s.name),
new ColumnInfo<XamlPathInfo>("path", typeof(string), null,(s) => s.path)
};
columnInfos.UpdateColumnIdx();
ExcelWorksheet sheet = GetSheet(p, "PATH");
sheet.Cells.Clear();
columnInfos.ToSheet(sheet, xamls);
}
void SaveToXlsxStringResources(ExcelPackage p, XamlPathInfo xamlInfo)
{
List<StringResource> stringResources = new List<StringResource>();
var xamlPath = System.IO.Path.Combine(rootPath, xamlInfo.path);
//加载 zh
var resourceDictionary = new ResourceDictionary() { Source = new Uri(xamlPath) };
foreach (string key in resourceDictionary.Keys)
{
var value = (string)resourceDictionary[key];
stringResources.Add(new StringResource() { key = key, zh = value });
}
//加载 en
var xamlPath_en = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(xamlPath), "en", System.IO.Path.GetFileName(xamlPath));
resourceDictionary = new ResourceDictionary() { Source = new Uri(xamlPath_en) };
foreach (string key in resourceDictionary.Keys)
{
var value = (string)resourceDictionary[key];
var stringResource = stringResources.Find(s => s.key == key);
if (stringResource == null)
{
//有中文,无英文
}
else
{
stringResource.en = value;
}
}
var columnInfos = new List<ColumnInfo<StringResource>>
{
new ColumnInfo<StringResource>("key", typeof(string), null, (s)=>s.key),
new ColumnInfo<StringResource>("zh", typeof(string), null, (s)=>s.zh),
new ColumnInfo<StringResource>("en", typeof(string), null, (s)=>s.en),
};
columnInfos.UpdateColumnIdx();
ExcelWorksheet sheet = GetSheet(p, xamlInfo.name);
sheet.Cells.Clear();
columnInfos.ToSheet(sheet, stringResources);
}
string Transfer(string msg)
{
if (msg.Contains("\n"))
{
msg = msg.Replace("\n", "&#x0a;");
Console.WriteLine($"转义 {msg}");
}
return msg;
}
void SaveToXlsxStringResources(ExcelPackage p, List<XamlPathInfo> xamlInfos)
{
List<StringResource> stringResources_all = new List<StringResource>();
foreach (var xamlInfo in xamlInfos)
{
List<StringResource> stringResources = new List<StringResource>();
var xamlPath = System.IO.Path.Combine(rootPath, xamlInfo.path);
//加载 zh
var resourceDictionary = new ResourceDictionary() { Source = new Uri(xamlPath) };
foreach (string key in resourceDictionary.Keys)
{
var value = (string)resourceDictionary[key];
if (key == "str.IBC.PgSystem.Base")
{
}
value = Transfer(value);
stringResources.Add(new StringResource() { name = xamlInfo.name, key = key, zh = value });
}
//加载 en
var xamlPath_en = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(xamlPath), "en", System.IO.Path.GetFileName(xamlPath));
resourceDictionary = new ResourceDictionary() { Source = new Uri(xamlPath_en) };
foreach (string key in resourceDictionary.Keys)
{
var value = (string)resourceDictionary[key];
value = Transfer(value);
var stringResource = stringResources.Find(s => s.key == key);
if (stringResource == null)
{
//有英文,无中文
Console.WriteLine($"{key} 不能找到 中文");
}
else
{
stringResource.en = value;
}
}
stringResources_all.AddRange(stringResources);
}
var columnInfos = new List<ColumnInfo<StringResource>>
{
new ColumnInfo<StringResource>("name", typeof(string), null, (s)=>s.name),
new ColumnInfo<StringResource>("key", typeof(string), null, (s)=>s.key),
new ColumnInfo<StringResource>("zh", typeof(string), null, (s)=>s.zh),
new ColumnInfo<StringResource>("en", typeof(string), null, (s)=>s.en),
new ColumnInfo<StringResource>("ru", typeof(string), null, (s)=>s.ru),
};
columnInfos.UpdateColumnIdx();
ExcelWorksheet sheet = GetSheet(p, "StringResources");
sheet.Cells.Clear();
columnInfos.ToSheet(sheet, stringResources_all);
}
ExcelWorksheet GetSheet(ExcelPackage p, string sheet_name)
{
ExcelWorksheet sheet = p.Workbook.Worksheets[sheet_name];
if (sheet == null)
{
sheet = p.Workbook.Worksheets.Add(sheet_name);
}
return sheet;
}
}
public class XamlPathInfo
{
public string name { get; set; }
public string path { get; set; }
public override string ToString()
{
return $"[{name}] {path}";
}
}
public class StringResource
{
public string name { get; set; }
public string key { get; set; }
public string zh { get; set; }
public string en { get; set; }
public string ru { get; set; }
public override string ToString()
{
return $"[{name}] [{key}] [{zh}] [{en}] [{ru}]";
}
}
public class ColumnInfo<T>
{
public string ColumnName;
public Type DataType;
public string Format;
public delegate object GetValueHanlder(T sender, int itemIdx);
GetValueHanlder getValue;
public bool IsArray = false;
public int ItemCount = 1;
public delegate string GetColumnNameHanlder(int itemIdx);
GetColumnNameHanlder getColumnName;
//相对于整个表,列序号,从0开始数
public int ColumnIdx;
public ColumnInfo(string columnName, Type dataType, string format, Func<T, object> getValue)
{
ColumnName = columnName;
DataType = dataType;
Format = format;
this.getValue = (s, i) => getValue(s);
}
public ColumnInfo(string columnName, Type dataType, string format, GetValueHanlder getValue)
{
ColumnName = columnName;
DataType = dataType;
Format = format;
this.getValue = getValue;
IsArray = false;
ItemCount = 1;
}
public ColumnInfo(GetColumnNameHanlder getColumnName, Type dataType, string format, int itemCount, GetValueHanlder getValue)
{
IsArray = true;
ItemCount = itemCount;
this.getColumnName = getColumnName;
DataType = dataType;
Format = format;
this.getValue = getValue;
}
public object GetValue(T sender)
{
return getValue(sender, 0);
}
public object GetValue(T sender, int index)
{
return getValue(sender, index);
}
public string GetColumnName(int index)
{
return getColumnName(index);
}
public string GetColumnName()
{
return ColumnName;
}
public int GetColumnIdx(int itemIdx)
{
return ColumnIdx + itemIdx;
}
public int GetColumnIdx()
{
return ColumnIdx;
}
}
public static class ColumnInfoExt
{
public static void UpdateColumnIdx<T>(this List<ColumnInfo<T>> columnInfos)
{
int colIndex = 0;
for (int i = 0; i < columnInfos.Count(); i++)
{
var columnInfo = columnInfos[i];
columnInfo.ColumnIdx = colIndex;
colIndex += columnInfo.ItemCount;
}
}
public static void ToSheet<T>(this List<ColumnInfo<T>> columnInfos, ExcelWorksheet sheet, IEnumerable<T> senders, Action<int> progressEvent = null)
{
int progress = 0;
int from_rowNumber = 1;
int rowNumber = from_rowNumber;
int from_colNumber = 1;
int to_rowNumber = 1;
int to_colNumber = 1;
//添加标题
for (int i = 0; i < columnInfos.Count(); i++)
{
var columnInfo = columnInfos[i];
if (!columnInfo.IsArray)
{
int colNumber = from_colNumber + columnInfo.GetColumnIdx();
sheet.Cells[rowNumber, colNumber].Value = columnInfo.GetColumnName();
sheet.Column(colNumber).Style.Numberformat.Format = columnInfo.Format;
if (to_colNumber < colNumber)
to_colNumber = colNumber;
}
else
{
for (int k = 0; k < columnInfo.ItemCount; k++)
{
int colNumber = from_colNumber + columnInfo.GetColumnIdx(k);
sheet.Cells[rowNumber, colNumber].Value = columnInfo.GetColumnName(k);
sheet.Column(colNumber).Style.Numberformat.Format = columnInfo.Format;
if (to_colNumber < colNumber)
to_colNumber = colNumber;
}
}
}
rowNumber++;
progressEvent?.Invoke(progress++);
foreach (var sender in senders)
{
for (int i = 0; i < columnInfos.Count(); i++)
{
var columnInfo = columnInfos[i];
if (!columnInfo.IsArray)
{
int colNumber = from_colNumber + columnInfo.GetColumnIdx();
var value = columnInfo.GetValue(sender);
if (value != null)
{
sheet.Cells[rowNumber, colNumber].Value = value;
}
}
else
{
for (int k = 0; k < columnInfo.ItemCount; k++)
{
int colNumber = from_colNumber + columnInfo.GetColumnIdx(k);
var value = columnInfo.GetValue(sender, k);
if (value != null)
{
sheet.Cells[rowNumber, colNumber].Value = value;
}
}
}
}
rowNumber++;
progressEvent?.Invoke(progress++);
}
to_rowNumber = rowNumber - 1;
using (var range = sheet.Cells[from_rowNumber, from_colNumber, to_rowNumber, to_colNumber])
{
range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
}
using (var range = sheet.Cells[from_rowNumber, from_colNumber, from_rowNumber, to_colNumber])
{
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
range.Style.Fill.BackgroundColor.SetColor(Color.Yellow);
range.AutoFitColumns();
}
}
}
}
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("WpfApp1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WpfApp1")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
//若要开始生成可本地化的应用程序,请设置
//.csproj 文件中的 <UICulture>CultureYouAreCodingWith</UICulture>
//在 <PropertyGroup> 中。例如,如果你使用的是美国英语。
//使用的是美国英语,请将 <UICulture> 设置为 en-US。 然后取消
//对以下 NeutralResourceLanguage 特性的注释。 更新
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(未在页面中找到资源时使用,
//或应用程序资源字典中找到时使用)
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
//(未在页面中找到资源时使用,
//、应用程序或任何主题专用资源字典中找到时使用)
)]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace WpfApp1.Properties
{
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfApp1.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WpfApp1.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{03F35DC4-998E-439F-A5E0-A2BB86B0B43D}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>WpfApp1</RootNamespace>
<AssemblyName>WpfApp1</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm">
<Version>8.3.2</Version>
</PackageReference>
<PackageReference Include="Costura.Fody">
<Version>5.7.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="EPPlus">
<Version>7.4.0</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody">
<Version>4.1.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment