我有一个动态"属性"的模型(在DB级别,类似于实体 - 属性 - 价值系统).属性位于字段中Dictionary<int, string>,并希望将它们显示为列.
该模型具有"属性"名称和键的静态数组(在静态反向器中初始化):
public static ModelSpecialParameter[] SpecialFields;
Run Code Online (Sandbox Code Playgroud)
和一个字典(在模型创建中初始化,并添加所有可用的键)及其值.
public Dictionary<int, string> ValuesForDynamicProps;
Run Code Online (Sandbox Code Playgroud)
@(Html.Kendo().Grid(Model)
.Name("grid")
.Columns(columns =>
{
//other columns for realy propertry
//columns.Bound(e => ...
//columns.Bound(e => ...
foreach (var item in SpecialFields) // SpecialFields is a static collection. represent the name an id of the dynamic property's.
{
columns.Bound("ValuesForDynamicProps[" + item.IdProperty + "]").Width(140).Title(item.DisplayName);
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
{"绑定列需要字段或属性访问表达式."}
我也尝试过:
columns.Bound(e => e.ValuesForDynamicProps[item.IdProperty]).Width(140).Title(item.DisplayName);
Run Code Online (Sandbox Code Playgroud)
同样的错误.
即使我想要的是不可能的,我也在寻找如何获得理想结果的想法:添加和删除属性的灵活性.
将 WPF 页面保存为 pdf 很简单
PrintDialog printDialog = new PrintDialog();
printDialog.PrintQueue = new PrintQueue(new PrintServer(), "Microsoft Print to PDF");
printDialog.PrintVisual(grid, "PrintDocument");
Run Code Online (Sandbox Code Playgroud)
但是我希望将 pdf 文档保存到预定义路径而不使用对话框是否有问题
我正在开发一个 C# 项目,我需要打开一个 Word 文档并对其进行搜索/替换,然后保存结果以供以后在 Word 本身中进行编辑。
这是一个独立的应用程序,而不是 Word 插件。
有没有简单的代码可以让我开始?
我已经搜索过,但没有发现任何有用的东西。
编辑:
看起来 nuget 包 DocX 可以满足我的需要。
当我在VS中发布时,它的消息是"Publish Failed".
输出:
启动Web部署将应用程序/包发布到https:// -myStite -... D:\ VisualStudio\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(4292,5):错误:Web部署任务失败.((30/10/2017 08:19:07)在远程计算机上处理请求时发生错误.)
(30/10/2017 08:19:07)在远程计算机上处理请求时发生错误.值不能为空.在System.Version.Parse(String输入),位于Microsoft的Microsoft.Web.Deployment.DeploymentAgentWorkerRequest.get_MaximumSupportedVersion()中的System.Version.ctor(String version),Microsoft的Microsoft.Web.Deployment.DeploymentAgent.HandleClientServerVersionMismatch(DeploymentAgentWorkerRequest workerRequest). Microsoft.Web.Deployment.DeploymentAgent.BeginProcessRequest(DeploymentAgentWorkerRequest workerRequest,AsyncCallback回调,Object extraData)上的Microsoft.Web.Deployment.DeploymentAgent.HandleRequest(DeploymentAgentAsyncData asyncData)中的Web.Deployment.DeploymentAgent.HandleRequestWorker(DeploymentAgentAsyncData asyncData)发布无法部署.
=========构建:1成功,0失败,0最新,0跳过========== =========发布:0成功, 1失败,0跳过==========
在服务器上的EventViwer中,此异常:
用户:-my user-客户端IP:10.0.0.138内容类型:版本:9.0.0.0 MSDeploy.VersionMin:MSDeploy.VersionMax:MSDeploy.Method:MSDeploy.RequestId:MSDeploy.RequestCulture:MSDeploy.RequestUICulture:ServerVersion:9.0.1955.0发生了传播到客户端的跟踪部署代理异常.请求ID''.索取时间戳:'30/10/2017 08:02:11'.错误详细信息:System.ArgumentNullException:值不能为null.参数名称:在Microsoft.Web.Deployment.DeploymentAgent.HandleClientServerVersionMismatch(DeploymentAgentWorkerRequest workerRequest)上的Microsoft.Web.Deployment.DeploymentAgentWorkerRequest.get_MaximumSupportedVersion()处的System.Version.ctor(String version)处输入System.Version.Parse(String input) )Microsoft.Web.Deployment.DeploymentAgent.HandleRequestWorker(DeploymentAgentAsyncData asyncData)at Microsoft.Web.Deployment.DeploymentAgent.HandleRequest(DeploymentAgentAsyncData asyncData)
在过去,他工作得很好(保存配置相同),现在有时会失败.
我对正则表达式的速度有很好的体验JS.
我决定做一个小比较.我运行了以下代码:
var str = "A regular expression is a pattern that the regular expression engine attempts to match in input text.";
var re = new RegExp("t", "g");
console.time();
for(var i = 0; i < 10e6; i++)
str.replace(re, "1");
console.timeEnd();
Run Code Online (Sandbox Code Playgroud)
结果:3888.731ms.
现在C#:
var stopwatch = new Stopwatch();
var str = "A regular expression is a pattern that the regular expression engine attempts to match in input text.";
var re = new Regex("t", RegexOptions.Compiled);
stopwatch.Start(); …Run Code Online (Sandbox Code Playgroud) 我发现Google Geocoding API服务非常有用。
但在所有示例中似乎有必要提出一个要求Key提供 google 的参数Api Key。这意味着它涉及成本,但我发现即使没有这种争论,它也能很好地工作。例子:
https://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
Run Code Online (Sandbox Code Playgroud)
你可以信赖吗?他们有什么限制吗?
我使用OpenXml读取Excel文件.一切正常,但如果电子表格包含一个具有地址邮件的单元格,并且在其后面有空格和另一个单词,例如:
abc@abc.com abc
它会在电子表格的开头立即抛出异常:
var _doc = SpreadsheetDocument.Open(_filePath, false);
Run Code Online (Sandbox Code Playgroud)
例外:
DocumentFormat.OpenXml.Packaging.OpenXmlPackageException
附加信息:
无效的超链接:格式错误的URI作为文档中的超链接嵌入.
我有一个带有几个项目的ComboBox.我想把SelectedIndexComboBox放到0,所以当用户启动它时,第一个项目已经被选中(默认).
但是,执行this(combobox.SelectedIndex = 0;)会干扰我的事件combobox_SelectedIndexChanged(),当用户更改ComboBox的SelectedIndex时,会发生重新启动程序:
private void combobox_SelectedIndexChanged(object sender, EventArgs e)
{
Process.Start(Application.ExecutablePath);
this.Close();
}
Run Code Online (Sandbox Code Playgroud)
这将导致combobox_SelectedIndexChanged()循环无穷,combobox.SelectedIndex = 0;将触发它,这将再次触发另一个等等......
在没有这种循环的情况下,有没有办法让程序在用户更改SelectedIndex时做一些事情?
我的项目对读取各种类型的Excel文件有新的要求。我可以使用Codeplex中的ExcelDataReader dll读取.xls和.xlsx文件。问题是当我尝试读取.xlsb文件时。ExcelDataReader无法从.xlsb文件读取。除了Microsoft.Office.Interop.Excel在基于服务器的应用程序中使用dll 之外,还有其他有效的读取xlsb文件的方法吗?
IExcelDataReader excelReader = fileName.EndsWith(".xlsx")
? ExcelReaderFactory.CreateOpenXmlReader(stream)
: ExcelReaderFactory.CreateBinaryReader(stream);
while (excelReader.Read())
{
//myStuff read the file
}
Run Code Online (Sandbox Code Playgroud) 我试图解析一个json来访问子值.以下是json示例,
jsondata = {
"sample_data": "{"o2:{"testname":"o2","department":"chemistry","normalvalue":"l","testmethod":"j","specimen":"g","referelprice":"y","normalprice":"i","discountprice":"o"}}"
}
Run Code Online (Sandbox Code Playgroud)
以下是我的代码
var _json = JObject.Parse(jsondata.ToString());
Console.WriteLine(_json["sample_data"]);
Run Code Online (Sandbox Code Playgroud)
这段代码给了我输出
{"o2":{"testname":"o2","department":"chemistry","normalvalue":"l","testmethod":"j","specimen":"g","referelprice":"y","normalprice":"i","discountprice":"o"}}
Run Code Online (Sandbox Code Playgroud)
现在如果我试图通过使用获得孩子"o2"
Console.WriteLine(_json [ "SAMPLE_DATA"] [ "O2"]);
我收到以下错误消息
cannot access child value on newtonsoft.json.linq.jvalue
Run Code Online (Sandbox Code Playgroud)
请帮助我了解如何获得孩子的价值.我希望输出像
{"testname":"o2","department":"chemistry","normalvalue":"l","testmethod":"j","specimen":"g","referelprice":"y","normalprice":"i","discountprice":"o"}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点.请帮忙.
c# ×6
excel ×2
.net ×1
asp.net-mvc ×1
combobox ×1
google-api ×1
iis-8 ×1
javascript ×1
json.net ×1
licensing ×1
ms-word ×1
openxml ×1
pdf ×1
regex ×1
telerik-mvc ×1
webdeploy ×1
winforms ×1
wpf ×1