我想使用Open XML SDK 2.0(CTP)更新图表使用的电子表格中的单元格.我找到的所有代码示例都插入了新的单元格.我正在努力检索正确的工作表.
public static void InsertText(string docName, string text, uint rowIndex,
string columnName)
{
// Open the document for editing.
using (SpreadsheetDocument spreadSheet =
SpreadsheetDocument.Open(docName, true))
{
Workbook workBook = spreadSheet.WorkbookPart.Workbook;
WorksheetPart worksheetPart = workBook.WorkbookPart.
WorksheetParts.First();
SheetData sheetData = worksheetPart.Worksheet.
GetFirstChild<SheetData>();
// If the worksheet does not contain a row with the specified
// row index, insert one.
Row row;
if (sheetData.Elements<Row>().Where(
r => r.RowIndex == rowIndex).Count() != 0)
// At this point I am expecting a match …Run Code Online (Sandbox Code Playgroud) 好.简单的问题.也许不是那么简单的回答:
我有一个用Java下载的文件,我知道它是一个文本文件.有什么方法可以使用Java在默认文本编辑器中打开该文本文件?它必须适用于所有操作系统,否则我只能用记事本打开它.
:\我想如果没有办法做到这一点,我可以使用JOptionPane并显示文本文件的内容......
我知道我可以打开多个文件,比如
with open('a', 'rb') as a, open('b', 'rb') as b:
Run Code Online (Sandbox Code Playgroud)
但我有一个情况,我有一个文件列表打开,我想知道当文件数量提前未知时,首选方法是做什么的.就像是,
with [ open(f, 'rb') for f in files ] as fs:
Run Code Online (Sandbox Code Playgroud)
(但是AttributeError因为列表没有实现而失败了__exit__)
我不介意使用像
try:
fs = [ open(f, 'rb') for f in files ]
....
finally:
for f in fs:
f.close()
Run Code Online (Sandbox Code Playgroud)
但是我不确定如果在尝试打开它们时抛出一些文件会发生什么.是否会fs在块中正确定义管理打开的文件finally?
我有以下代码打开谷歌地图:
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@, Anchorage, AK",addressString];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
Run Code Online (Sandbox Code Playgroud)
但它不起作用,没有错误.它只是没有打开.
为什么我得到"autodie"不同的输出?
#!/usr/bin/env perl
use warnings;
use 5.012;
use utf8;
use open ':encoding(utf-8)';
use open ':std';
open my $fh, '>', 'test.txt' or die $!;
say $fh 'käse';
close $fh;
open my $fh1, '<', 'test.txt' or die $!;
while ( my $row = readline( $fh1 ) ) {
print $row;
}
close $fh1;
use autodie;
open my $fh2, '<', 'test.txt';
while ( my $row = readline( $fh2 ) ) {
print $row;
}
close $fh2;
# Output:
# käse
# käse
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个实用程序类,允许自动调整tiletale图像的大小.假设有一个srcBitmap,我从中复制一个由Rectangle srcRegion给出的区域.然后我想在目标区域Rectangle destRegion中将该区域粘贴(明智的像素)到另一个名为Bitmap destBitmap的图像中.我知道如何从源中获取区域并将其放入Bitmap对象中,但我还没有找到如何将Bitmap对象实际粘贴到另一个更大的Bitmap对象中的某个区域中.
有快速的方法吗?(没有GDI而没有深入研究位图的字节数组).这是应该澄清我的目标的片段
private static void CopyRegionIntoImage(Bitmap srcBitmap, Rectangle srcRegion, Bitmap destBitmap, Rectangle destRegion)
{
// get the required region from the destination
Bitmap region = Copy(srcBitmap, srcRegion);
}
Run Code Online (Sandbox Code Playgroud) 我基本上想测试stdin是否有输入(如果你回显并管道它).我找到了有效的解决方案,但它们很难看,而且我喜欢我的解决方案.
在linux上我用这个:
bool StdinOpen() {
FILE* handle = popen("test -p /dev/stdin", "r");
return pclose(handle) == 0;
}
Run Code Online (Sandbox Code Playgroud)
我知道我应该添加更多的错误处理,但除此之外.
在Windows上我用这个:
bool StdinOpen() {
static HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
DWORD bytes_left;
PeekNamedPipe(handle, NULL, 0, NULL, &bytes_left, NULL);
return bytes_left;
}
Run Code Online (Sandbox Code Playgroud)
对于linux来说这很好,但我想知道在不使用管道的情况下我可以调用的等效API(就像test -f $file你一样fopen($file, "r") != NULL).我有能力open("/dev/stdin", "r")和做同样的事情,但我想知道最好的方法.
简介:我想知道可以用来代替test -p /dev/stdinlinux 的API ,如果你知道一个更好的Windows解决方案.
(我在这个例子中使用了pyprocessing模块,但是如果你运行python 2.6或使用多处理backport,那么用多处理替换处理应该可以工作)
我目前有一个程序,它监听一个unix套接字(使用processing.connection.Listener),接受连接并产生一个处理请求的线程.在某一点上,我想优雅地退出该过程,但由于accept() - 调用是阻塞的,我认为没有办法以一种很好的方式取消它.我有一种方法在这里工作(OS X)至少,设置信号处理程序并从另一个线程发信号通知过程如下:
import processing
from processing.connection import Listener
import threading
import time
import os
import signal
import socket
import errno
# This is actually called by the connection handler.
def closeme():
time.sleep(1)
print 'Closing socket...'
listener.close()
os.kill(processing.currentProcess().getPid(), signal.SIGPIPE)
oldsig = signal.signal(signal.SIGPIPE, lambda s, f: None)
listener = Listener('/tmp/asdf', 'AF_UNIX')
# This is a thread that handles one already accepted connection, left out for brevity
threading.Thread(target=closeme).start()
print 'Accepting...'
try:
listener.accept()
except …Run Code Online (Sandbox Code Playgroud) 我正在编写一个将输出写入文件的程序.如果此文件不存在,我想创建它.
目前,我在调用open时使用以下标志:O_WRONLY | O_CREATE
但是,当这创建文件时,它不会给我任何写入它的权限...
我如何使用open以便在不存在的情况下创建文件,但是在需要时会创建具有必要权限的文件?
谢谢!
我正在研究一个Linux C项目,我在使用文件描述符时遇到了麻烦.
我有一个孤立文件描述符(文件是open()'然后取消链接()'但fd仍然很好)具有只写权限.原始后备文件具有完全权限(使用S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH创建),但是文件是使用O_WRONLY打开的.是否可以复制文件描述符并将副本更改为O_RDWR?
psudo代码:
//open orphan file
int fd = open(fname, O_WRONLY, ...)
unlink(fname)
//fd is still good, but I can't read from it
//...
//I want to be able to read from orphan file
int fd2 = dup(fd)
//----change fd2 to read/write???----
Run Code Online (Sandbox Code Playgroud)
提前致谢!-安德鲁