我想克隆一个通用对象并保留其类型。
run.Append(style.Clone(BlackFont)); //run object accepts only RunProperties objects
public T Clone(T what) {
if (what is RunProperties)
return (T) what.Clone();
}
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为 T 类型没有 Clone 方法,我怎样才能在没有在第一个语句中进行转换的情况下克服这个问题。
run.Append((RunProperties) style.Clone(BlackFont)); //I do not want this
//not that this will work since you can't convert T to RunProperties
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。
- -编辑 - -
在这种情况下,我最好不要使用泛型。我会拆分数据。
我需要将 Excel 文档嵌入到 Word 文档中。我使用了这个问题的答案 -> How can I embed any file type into Microsoft Word using OpenXml 2.0;
一切正常,除了:
DrawAspect = OVML.OleDrawAspectValues.Icon允许您通过打开新的 Excel 实例来编辑 Excel 对象。但是,当我编辑数据时,它不会在Word文档中更新。
DrawAspect = OVML.OleDrawAspectValues.Content允许您直接在 Word 文档中编辑 Excel 对象。
我的问题是,我必须在代码中更改哪些内容,以便我可以在新实例中编辑 Excel 对象并将其正确反映在 Word 文档中?我尝试了一切都无济于事。
有件事告诉我,DrawAspect = OVML.OleDrawAspectValues.Icon该对象充当图标,并且更改无法正确反映在该图标中。
我正在尝试计算文档中有多少元素:
Iterator<?> processDescendants = doc.getDescendants(new ElementFilter("a"));
while(processDescendants.hasNext()) {
numPending++;
}
processDescendants = doc.getDescendants(new ElementFilter("b"));
while(processDescendants.hasNext()) {
numPending++;
}
Run Code Online (Sandbox Code Playgroud)
必须有一种更简单的方法......例如:
processDescendants = doc.getDescendants(new ElementFilter("a|b")); // something like Regex maybe?
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?谢谢.
当我注意到这段代码时,试图弄清楚函数中的堆栈损坏错误:
fprintf( fp, "\n%s %3c %12s %2c %12s %2c %12s %2c %12s %2c"
"%12s %2c %12s",
xys_field[3], x,
xyzFunc(val1, 0), x,
xyzFunc(val2, 0), x,
xyzFunc(val3, 0), x,
xyzFunc(val4, 0), x,
xyzFunc(val5, 0), x,
xyzFunc(val6,0) );
Run Code Online (Sandbox Code Playgroud)
我问的是关于这一行"\n%s %3c %12s %2c %12s %2c %12s %2c %12s %2c" "%12s %2c %12s",我甚至不明白这是如何编译的,因为我从未见过两种格式如此相互跟随.谢谢你的帮助.
我正在使用NET 3.5 库System.Drawing.Bitmap中的类System.Drawing。
代码是这样的:
Bitmap bm = new Bitmap(filename);
Console.WriteLine("bm.width: " + bm.width); // RETURNS 233, RIGHT AMOUNT
Console.WriteLine("bm.HorizontalResolution: " + bm.HorizontalResolution); // RETURNS 0!!
Run Code Online (Sandbox Code Playgroud)
有谁有我可以使用的不同兼容类,或者单声道的任何技巧可以使这项工作正常进行?我需要在 Word 中正确缩放图像的分辨率(我正在生成 .docx 文件)。
Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4ubuntu1)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
Run Code Online (Sandbox Code Playgroud)
System.Drawing.Image具有相同的行为。
我正在生成迷宫,我只能选择第一列或最后一列.我只能选择偶数行(如果你在1处开始行索引).我有正确的逻辑,除了迷宫开始位置不是随机的.如果我生成50个迷宫,那些都是20x20,所有起始位置都是相同的.任何帮助将不胜感激.谢谢.
void Maze::generatePath()
{
int startingColumn = -1;
int startingRow = -1;
srand (time(NULL));
int side = rand() % 2;
startingColumn = (width - 1) * side; // will get first or last column
int row = rand() % height; // 0 -> height - 1
if(row % 2 == 0) // even, add one, or subtract if last row
{
if(row + 1 >= width)
startingRow = row - 1;
else
startingRow = row + 1;
}
else
{ …Run Code Online (Sandbox Code Playgroud) import java.util.GregorianCalendar;
public class FullYear {
public static void main(String[] args) {
GregorianCalendar cal1 = new GregorianCalendar(2011,2,9);
GregorianCalendar cal2 = new GregorianCalendar(2011,2,12);
long ms1 = cal1.getTime().getTime();
long ms2 = cal2.getTime().getTime();
long difMs = ms2-ms1;
long msPerDay = 1000*60*60*24;
System.out.println(difMs);
System.out.println(msPerDay);
double days = difMs / msPerDay;
System.out.println(days);
GregorianCalendar cal11 = new GregorianCalendar(2011,2,9);
GregorianCalendar cal22 = new GregorianCalendar(2011,2,19);
long ms11 = cal11.getTime().getTime();
long ms22 = cal22.getTime().getTime();
long difMs1 = ms22-ms11;
long msPerDay1 = 1000*60*60*24;
System.out.println(difMs1);
System.out.println(msPerDay1);
double days2 = difMs1 / …Run Code Online (Sandbox Code Playgroud) public class Log {
private static StringBuilder log = new StringBuilder();
private static StringBuilder getLog() {
return log;
}
public static void addToLog(String id, String name, String field, String operator, String value, String bValue) {
Calendar calendar = Calendar.getInstance();
String currentTime = formatter.format(calendar.getTime());
getLog().append(currentTime); // line 114
}
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
[java] Exception in thread "Thread-5" java.lang.ArrayIndexOutOfBoundsException
[java] at java.lang.String.getChars(String.java:863)
[java] at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:416)
[java] at java.lang.StringBuilder.append(StringBuilder.java:132)
[java] at com.retroficiency.system.Log.addToMatchingLog(Log.java:114)
Run Code Online (Sandbox Code Playgroud)
这种方法通常工作正常,但我们遇到了这个随机错误,我无法弄清楚为什么.有一个单独的方法可以将日志刷新到文件并使用以下方法清除它:
getLog().delete(0, getMatchingLog().length());
Run Code Online (Sandbox Code Playgroud)
我不认为这是一个Java bug?它变得太长了吗?谢谢你的帮助!
据说线程永远不应该在构造函数中启动,但我不确定在这种情况下this引用如何转义Test构造函数.我查看了底层的Thread.java,我无法弄清楚这一点.
class Test {
static MyThread thread;
public Test() {
thread = new MyThread();
thread.start();
}
}
class MyThread extends Thread {
public void run() {
//do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助.
thread = new MyThread();会调用Thread超级构造函数:
public Thread() {
init(null, null, "Thread-" + nextThreadNum(), 0);
}
Run Code Online (Sandbox Code Playgroud)
我没有看到参考文献的消失.
我有一个TreeMap <DDate, Integer>.
DDate只包含月份和年份(月份为0索引,如Java,JAN = 0);
我的比较并没有回归正确的事情:
@Override
public int compareTo(DDDate o) {
Calendar cal1 = Calendar.getInstance();
cal1.setTimeZone(TimeZone.getTimeZone("UTC"));
cal1.set(year, month, 1); // year is 2012, month is 1
Calendar cal2 = Calendar.getInstance();
cal2.setTimeZone(TimeZone.getTimeZone("UTC"));
cal2.set(o.getYear(), o.getMonth(), 1); // year is 2012, month is 1
Log.log("COMPARING: " + format.format(cal1.getTime())); // COMPARING: 20120101
Log.log("COMPARING: " + format.format(cal2.getTime())); // COMPARING: 20120101
Log.log((cal1.getTime().getTime())); // 1325413927678
Log.log((cal2.getTime().getTime())); // 1325413927679
Log.log("WILL RETURN: " + cal1.getTime().compareTo(cal2.getTime())); // WILL RETURN: -1
return cal1.getTime().compareTo(cal2.getTime());
}
Run Code Online (Sandbox Code Playgroud)
为什么同一日期的两个Calendar对象中存在缺陷?(1325413927678 vs 1325413927679)
谢谢! …
我需要一个 Azure Functions blob 触发器来触发应用设置在运行时提供的存储桶。我读到可以这样做:
[FunctionName("Process")]
public static async Task Process([BlobTrigger("%BucketName%/{name}", Connection = "AzureWebJobsStorage")] Stream avroBlobStream, string name, TraceWriter log)
{
}
Run Code Online (Sandbox Code Playgroud)
如果我BucketName只有Values在 appsettings.json的字段中,这在本地工作。
{
"IsEncrypted": false,
"Values": {
"BucketName": "capture-bucket",
}
}
Run Code Online (Sandbox Code Playgroud)
如果它不在 Values 字段中,则这是错误:
[6/24/2019 5:52:15 PM] Function 'SomeClass.Process' failed indexing and will be disabled.
[6/24/2019 5:52:15 PM] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the …Run Code Online (Sandbox Code Playgroud)