我将格式化单元格设置为日期时遇到问题.
FileInfo info = new FileInfo(path);
using (ExcelPackage package = new ExcelPackage(info))
{
ExcelWorksheet ws = package.Workbook.Worksheets.Add(sheetName);
ws.Cells[3, 1].Style.Numberformat.Format = "yyyy-mm-dd";
ws.Cells["A3"].Formula = "=DATE(2014,10,5)";
}
Run Code Online (Sandbox Code Playgroud)
在Excel中输出:41 917,00
为什么这不起作用?
我有一个带有静态构造函数的静态类.我需要以某种方式将参数传递给这个静态类,但我不确定最好的方法是什么.你会推荐什么?
public static class MyClass {
static MyClass() {
DoStuff("HardCodedParameter")
}
}
Run Code Online (Sandbox Code Playgroud) 我正试图杀死远程机器上的进程.但我得到错误.我做错了什么,我该怎么做才能做到这一点?
我的代码:
var iu = new ImpersonateUser();
try
{
iu.Impersonate(Domain, _userName, _pass);
foreach (var process in Process.GetProcessesByName("notepad", "RemoteMachine"))
{
string processPath = pathToExe; //Is set as constant (and is correct)
process.Kill();
Thread.Sleep(3000);
Process.Start(processPath);
}
}
catch (Exception ex)
{
lblStatus.Text = ex.ToString();
}
finally
{
iu.Undo();
}
Run Code Online (Sandbox Code Playgroud)
只是为了澄清ImpersonateUser,它让我以正确的用户权限登录到远程机器.所以问题不存在.当我调试并检查过程对象时,在这种情况下我找到了记事本的正确进程ID.所以连接工作正常.但是当我试图杀死进程时,我得到了这个错误:
System.NotSupportedException: Feature is not supported for remote machines. at System.Diagnostics.Process.EnsureState
Run Code Online (Sandbox Code Playgroud) 我有一个web api,我有2个方法,一个没有参数,两个有不同类型的参数(字符串和整数).调用字符串方法时它不起作用...我在这里缺少什么?
public class MyControllerController : ApiController
{
public IHttpActionResult GetInt(int id)
{
return Ok(1);
}
public IHttpActionResult GetString(string test)
{
return Ok("it worked");
}
}
Run Code Online (Sandbox Code Playgroud)
WebApiConfig.cs:
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Run Code Online (Sandbox Code Playgroud)
我的电话:
/ api/MyController/MyString //不起作用
/ api/MyController/1 //工作
我收到以下错误:
参数字典包含'TestAngular.Controllers.MyControllerController'中方法'System.Web.Http.IHttpActionResult GetInt(Int32)'的非可空类型'System.Int32'的参数'id'的空条目.可选参数必须是引用类型,可空类型,或者声明为可选参数.
我的请求中缺少什么?
我正在使用HyperLinkField
内部a gridview
,我想链接到另一个URL +一个ID.
<div id="searchResults" runat="server">
<asp:GridView ID="gvSearchResult" runat="server" AutoGenerateColumns = "false"
CaptionAlign="NotSet" CellPadding="5">
<Columns>
<asp:TemplateField HeaderText="Användare">
<ItemTemplate>
<%# Eval("UName")%>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="UName"
DataNavigateUrlFormatString='/MemberPages/profile.aspx?ID=<%# Eval("PID") %>'
DataTextField="UName"
HeaderText="Besök sida"
SortExpression="Name"
ItemStyle-Width="100px"
ItemStyle-Wrap="true" />
</Columns>
</asp:GridView>
</div>
Run Code Online (Sandbox Code Playgroud)
在gridview
使用datasource
和databind
.它在抱怨:
DataNavigateUrlFormatString="/MemberPages/profile.aspx?ID=<%# Eval("PID") %>"
Run Code Online (Sandbox Code Playgroud)
我不知道在哪里使用<%# Eval("PID") %>
,我确定有类似PID的东西,我已经进行了双重检查.
如果我正在使用NavigateUrl="/MemberPages/profile.aspx?ID=<%# Eval("PID") %>"
我也会得到同样的错误:
Literal content ('<asp:HyperLinkField DataNavigateUrlFields="UName"
DataNavigateUrlFormatString="/MemberPages/profile.aspx?ID=') is not allowed within a 'System.Web.UI.WebControls.DataControlFieldCollection'.
Run Code Online (Sandbox Code Playgroud) 我正在使用VS 2015,当我在编写javascript时在代码行后按Enter键时,我总是在开始时开始下一行.我希望它从"适当"的地方开始,例如
function newLine() {
Starts here..//Works fine
}
Starts here now..
Run Code Online (Sandbox Code Playgroud)
编辑:通过"应该从这里开始..."我的意思是从大括号中的一个选项卡,而不是下面的两行:)
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
var fP18VaR = (float) (int)e.Values[0];
}
Run Code Online (Sandbox Code Playgroud)
我越来越
InvalidCastException - 指定的强制转换无效
为什么不起作用?
e.Values [0]的值是:6 666,00
我正在尝试编写一个查询,检查2个数量是否具有相同的符号(+或 - ).你有一个可以使用的好解决方案吗?
类似的东西:如果SAMESIGN(value1,value2)然后做一些事情
对不起,但我不知道该怎么称呼它...
我有一张桌子看起来像这样:
+-----++-----+
| Id ||Count|
+-----++-----+
| 1 || 1 |
+-----++-----+
| 2 || 5 |
+-----++-----+
| 3 || 8 |
+-----++-----+
| 4 || 3 |
+-----++-----+
| 5 || 6 |
+-----++-----+
| 6 || 8 |
+-----++-----+
| 7 || 3 |
+-----++-----+
| 8 || 1 |
+-----++-----+
Run Code Online (Sandbox Code Playgroud)
我试图从这个表中做出一个选择,每次row1 + row2 + row3(等)的SUM达到10,那么它就是一个"HIT",并且计数重新开始.
请求的输出:
+-----++-----++-----+
| Id ||Count|| HIT |
+-----++-----++-----+
| 1 || 1 || N | Count = 1
+-----++-----++-----+
| …
Run Code Online (Sandbox Code Playgroud) 我正在寻找将字符串转换为可执行代码的解决方案.我的代码非常慢,并执行4.7 seconds
.有没有更快的方法呢?
字符串:"5*5"
产量:25
代码:
class Program {
static void Main(string[] args) {
var value = "5 * 5";
Stopwatch sw = new Stopwatch();
sw.Start();
var test = Execute(value);
sw.Stop();
Debug.WriteLine($"Execute string at: {sw.Elapsed}");
}
private static object Execute(string content) {
var codeProvider = new CSharpCodeProvider();
var compilerParameters = new CompilerParameters {
GenerateExecutable = false,
GenerateInMemory = true
};
compilerParameters.ReferencedAssemblies.Add("system.dll");
string sourceCode = CreateExecuteMethodTemplate(content);
CompilerResults compilerResults = codeProvider.CompileAssemblyFromSource(compilerParameters, sourceCode);
Assembly assembly = compilerResults.CompiledAssembly;
Type type = assembly.GetType("Lab.Cal");
MethodInfo …
Run Code Online (Sandbox Code Playgroud) c# ×7
sql ×2
t-sql ×2
asp.net ×1
class ×1
epplus ×1
gridview ×1
hyperlink ×1
kill-process ×1
performance ×1
process ×1
sql-server ×1
static ×1