我需要完全隐藏excel列.我使用下面的代码,但没有工作:
public void Hide (params string[] columns)
{
foreach(var column in columns)
{
Range range = (Range) oSheet.Columns[column, Type.Missing];
range.EntireColumn.Hidden = true;
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
这个:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx
...表示我应该在KeyPress事件中访问e.KeyCode,但我似乎没有.我试图只允许1,2,3和退格:
private void textBoxQH1_KeyPress(object sender, KeyPressEventArgs e) {
if ((e.KeyChar != '1') &&
(e.KeyChar != '2') &&
(e.KeyChar != '3') &&
(e.KeyChar != (Keys.Back))) {
e.Handled = true;
}
}
Run Code Online (Sandbox Code Playgroud)
......但是"e." 没有显示像示例所示的"KeyCode"值,并且尝试使用Keys.Back的KeyChar骂我,"运算符'!='不能应用于'char'和'System.Windows.Forms.Keys'类型的操作数"
那我该怎么做呢?
可能重复:
在循环内部或外部声明变量是否更好?
Resharper要我改变这个:
int Platypus;
string duckBill1;
string duckBill2;
string duckBill3;
. . .
using (OracleDataReader odr = ocmd.ExecuteReader()) {
while (odr.Read()) {
Platypus = odr.GetInt32("Platypus");
duckBill1 = odr.GetString("duckBill1");
duckBill2 = odr.GetString("duckBill2");
duckBill3 = odr.GetString("duckBill3");
switch (Platypus) {
. . .
Run Code Online (Sandbox Code Playgroud)
......对此:
using (OracleDataReader odr = ocmd.ExecuteReader()) {
while (odr.Read()) {
int Platypus = odr.GetInt32("Platypus");
string duckBill1 = odr.GetString("duckBill1");
string duckBill2 = odr.GetString("duckBill2");
string duckBill3 = odr.GetString("duckBill3");
switch (Platypus) {
. . .
Run Code Online (Sandbox Code Playgroud)
......但是以这种方式(似乎,至少,似乎),vars被声明N次,每次通过while循环一次.Resharperized方式真的比原来好吗?
我需要连接到我的Windows商店应用程序和WP8应用程序之间的中间层(想想Azure).Windows Azure移动服务已被提供为解决方案.
但我是否在阅读"...... MOBILES服务"这一名称(因为其中一件不是移动应用,而是在台式机,笔记本电脑和平板电脑上运行)?
就我而言,我最好使用Azure云服务而不是Windows Azure移动服务?
cloud azure windows-phone azure-mobile-services windows-store-apps
这段代码在我的WP8应用程序中工作正常:
void App_UnhandledException(object sender, UnhandledExceptionEventArgs args)
{
string appName;
string appVersion;
var xmlReaderSettings = new XmlReaderSettings
{
XmlResolver = new XmlXapResolver()
};
using (var xmlReader = XmlReader.Create("WMAppManifest.xml", xmlReaderSettings))
{
xmlReader.ReadToDescendant("App");
appName = xmlReader.GetAttribute("Title");
appVersion = xmlReader.GetAttribute("Version");
}
WAMS_EXCEPTIONLOG wamsel = new WAMS_EXCEPTIONLOG
{
appNameAndVersion =
string.Format("{0} {1}", appName,
appVersion),
ExceptionMsg =
args.ExceptionObject.Message,
InnerException =
args.ExceptionObject
.InnerException.ToString(),
ExceptionToStr =
args.ExceptionObject.ToString(),
dateTimeOffsetStamp =
DateTimeOffset.UtcNow
};
await MobileService.GetTable<TASLS_WAMS_EXCEPTIONLOG>().InsertAsync(wamsel);
}
Run Code Online (Sandbox Code Playgroud)
...但在我的补充Windows商店应用程序中,几个类和类成员无法识别,即:
XmlResolver
XmlXapResolver
args.ExceptionObject
Run Code Online (Sandbox Code Playgroud)
(更不用说不允许等待的事实,并且向事件处理程序添加"async"会导致事件处理程序的赋值变为"变为红色")...
那么,回到主要观点:我如何通过我的Windows Store应用程序获得与WP8应用程序相同的功能?
c# exception-handling xml-parsing windows-phone-8 windows-store-apps
我一直试图解决这个问题很长一段时间,我仍然没有更聪明.我有以下方法:
public IResult Parse(string[] args)
{
var argumentOption = new ArgumentOption(_dataModelBinder);
var boundArgumentOption = argumentOption.Bind(args);
var bindingResults = boundArgumentOption.Validate(_argumentOptionValidator);
// AREA OF INTEREST
if (bindingResults.Any())
{
return new ErrorResult();
}
return new CreateReportResult(
_resultActioner
, boundArgumentOption.OutputFilePath
, boundArgumentOption.PatientId
, "database");
}
Run Code Online (Sandbox Code Playgroud)
我遇到麻烦的代码涉及到我正在创建的返回值,理想情况下我想留给温莎城堡处理.那么,我接下来要创建一个抽象工厂:
public interface IResultFactory
{
IResult Create(int numOfErrors);
}
public class ResultFactory : IResultFactory
{
private readonly IWindsorContainer _container;
public ResultFactory(IWindsorContainer container)
{
_container = container;
}
public IResult Create(int numOfErrors)
{
if (numOfErrors > 0)
{
return _container.Resolve<IResult>("ErrorResult"); …Run Code Online (Sandbox Code Playgroud) 我试图找出为什么从我的手持设备(Windows CE/Compact Framework)发送的REST调用没有进入我的服务器应用程序(在我的PC上运行的常规,完整的.NET应用程序).
手持设备和PC已连接 - 我知道因为我可以在PC的Windows资源管理器中看到手持设备,Windows Mobile Device Center会验证两者之间的连接是否有效等.
当我通过Postman传递相同的REST调用时,我到达我的PC上运行的服务器应用程序的断点,即:
http://192.168.125.50:21609/api/inventory/sendXML/duckbill/platypus/poisontoe
Run Code Online (Sandbox Code Playgroud)
...但是当从手持设备呼叫时不是这样.
所以,我想在wireshark中看到邮递员发送的内容,因此我可以看到在尝试从手持设备调用相同的REST方法时要查找的内容.
我在wireshark中设置了一个过滤器,即" ip.dst == 192.168.125.50"并在通过Postman调用方法时获得了一些结果,但我没有看到"端口21609",这是我期望的.如果我看到这个,我会知道我正在看正确的数据包,但......它在哪里?当我运行Postman并进行调用时,Wireshark捕获了四个数据包,并且没有一个数据包作为"用户数据报协议"元素中的端口号.
如果忽略端口号,我如何确定哪个数据包来自Postman?
Yoel有个好主意; 我添加了"Dest port(unresolved)"和"Sourceport"作为要显示的列.
然后我在Wireshark中开始了一个新的实时捕获,并从Postman发送了URL/REST方法.
服务器应用程序中的断点确实受到了影响.我通过它F5,并停止了Wireshark捕获.
在任何地方的Dest Port列中都看不到"21609".
为什么?如何发送URL,但Wireshark没有检测到它所指向的端口?
另外,在Wireshark的Protocol列中,我看不到"HTTP"条目.
我正在使用此方法在Web API项目中下载Excel文件(在Winforms应用程序中动态创建并保存到数据库中):
[Route("api/deliveryperformance/{unit}/{begindate}/{enddate}")]
public HttpResponseMessage Get(string unit, string begindate, string enddate)
{
// adapted the first part of this code from http://stackoverflow.com/questions/11176066/how-do-i-insert-retrieve-excel-files-to-varbinarymax-column-in-sql-server-2008
byte[] excelContents;
string selectStmt = "SELECT BinaryData FROM ReportsGenerated WHERE FileBaseName = @fileBaseName";
string fbn = string.Format("deliveryperformance/{0}/{1}/{2}", unit, begindate, enddate);
using (SqlConnection connection = new SqlConnection(ProActWebReportsConstsAndUtils.CPSConnStr))
using (SqlCommand cmdSelect = new SqlCommand(selectStmt, connection))
{
cmdSelect.Parameters.Add("@fileBaseName", SqlDbType.VarChar).Value = fbn;
connection.Open();
excelContents = (byte[])cmdSelect.ExecuteScalar();
connection.Close();
}
string excelFileName = "C:\\Misc\\TestFile2.xlsx";
File.WriteAllBytes(excelFileName, excelContents);
String HtmlToDisplay = GetDownloadSuccessMessage(excelFileName);
return new HttpResponseMessage()
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用互操作写一个Excel表.在表格中,我需要将一组句子放入单元格中.文本应采用换行方式.我怎样才能做到这一点?
提前致谢.
我有一个Web API方法,需要两个双参数:
存储库界面:
public interface IInventoryItemRepository
{
. . .
IEnumerable<InventoryItem> GetDepartmentRange(double deptBegin, double deptEnd);
. . .
}
Run Code Online (Sandbox Code Playgroud)
库:
public IEnumerable<InventoryItem> GetDepartmentRange(double deptBegin, double deptEnd)
{
// Break the doubles into their component parts:
int deptStartWhole = (int)Math.Truncate(deptBegin);
int startFraction = (int)((deptBegin - deptStartWhole) * 100);
int deptEndWhole = (int)Math.Truncate(deptEnd);
int endFraction = (int)((deptBegin - deptEndWhole) * 100);
return inventoryItems.Where(d => d.dept >= deptStartWhole).Where(e => e.subdept >= startFraction)
.Where(f => f.dept <= deptEndWhole).Where(g => g.subdept >= endFraction);
}
Run Code Online (Sandbox Code Playgroud)
控制器: …
c# ×8
excel ×2
asp.net ×1
azure ×1
cloud ×1
com ×1
com-interop ×1
double ×1
download ×1
filesystems ×1
keycode ×1
keypress ×1
optimization ×1
port ×1
postman ×1
resharper ×1
rest ×1
winforms ×1
wireshark ×1
xml-parsing ×1