我正在使用oledb连接将Excel工作表导入DataTable,如下所示.
private static DataTable UploadExcelSheet(string fileName)
{
DataTable uploadDataTable;
using (OleDbConnection objXConn = new OleDbConnection())
{
objXConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName +
";Extended Properties=\"Excel 12.0;IMEX=1\"";
objXConn.Open();
OleDbCommand objCommand =
new OleDbCommand("SELECT * FROM Template$ ", objXConn);
OleDbDataAdapter objDataAdapter = new OleDbDataAdapter();
// retrieve the Select command for the Spreadsheet
objDataAdapter.SelectCommand = objCommand;
// Create a DataSet
DataSet objDataSet = new DataSet();
// Populate the DataSet with the spreadsheet worksheet data
objDataAdapter.Fill(objDataSet);
uploadDataTable = objDataSet.Tables[0];
}
return uploadDataTable;
}
Run Code Online (Sandbox Code Playgroud)
一切都运行正常,但是当用户在上传excel之前删除几行内容时会出现问题.它还会读取这些空行以及非空行,并且由于业务规则违规(缺少必填字段),因此在数据库中保存数据失败.我尝试的是在查询中放置条件: …
所以我是C#的新手,我很难理解out.而不是仅仅从函数返回一些东西
using System;
class ReturnTest
{
static double CalculateArea()
{
double r=5;
double area = r * r * Math.PI;
return area;
}
static void Main()
{
double output = CalculateArea();
Console.WriteLine("The area is {0:0.00}", output);
}
}
Run Code Online (Sandbox Code Playgroud)
与此相比
using System;
class ReturnTest
{
static void CalculateArea(out double r)
{
r=5;
r= r * r * Math.PI;
}
static void Main()
{
double radius;
CalculateArea(out radius);
Console.WriteLine("The area is {0:0.00}",radius );
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
第一个是我一般会这样做的.我有可能想要使用out而不仅仅是返回语句吗?我理解ref …
鉴于此表:

那些是时间线(时间片= 4):
|p1|p1|p2|p3|p4|p5|p1|p2|p3|p4|p5|p2|p3|p4|p5|p2|p3|p4|p5|p2|p3|p3|
0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 69 72 75 79 80
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法来计算平均等待时间?
谢谢
注意:每个过程有几个完成时间!
注2:此问题还涉及优先级算法作为辅助练习,请忽略循环算法的优先级列
我目前使用这样的东西在单元格中插入内联字符串:
new Cell()
{
CellReference = "E2",
StyleIndex = (UInt32Value)4U,
DataType = CellValues.InlineString,
InlineString = new InlineString(new Text( "some text"))
}
Run Code Online (Sandbox Code Playgroud)
但是\n插入换行符不起作用,我该怎么做呢?
谢谢
响应
new Cell(
new CellValue("string \n string")
)
{
CellReference = "E2",
StyleIndex = (UInt32Value)4U,
DataType = CellValues.String
}
Run Code Online (Sandbox Code Playgroud) 我已经编写了一些代码来模拟我正在使用的一些硬件并将其上传到Arduino板.这段代码有效.我知道这一点,因为我得到了HyperTerminal的预期响应.
但是,当我尝试使用PySerial进行连接时,连接不会出错,但我对我发送的命令没有响应.
为什么会这样?
Python代码
import serial
def main():
sp = serial.Serial()
sp.port = 'COM4'
sp.baudrate = 19200
sp.parity = serial.PARITY_NONE
sp.bytesize = serial.EIGHTBITS
sp.stopbits = serial.STOPBITS_ONE
sp.timeout = 0.5
sp.xonxoff = False
sp.rtscts = False
sp.dsrdtr = False
sp.open()
sp.write("GV\r\n".encode('ascii'))
value = sp.readline()
print value
sp.write("GI\r\n".encode('ascii'))
value = sp.readline()
print value
sp.close()
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
注意:Arduino上的代码在对\r\n命令的响应结束时发回.
超级终端配置:

我发现如果我将超时增加到10秒并sp.readline()在发送任何内容之前添加一个,那么我会得到对这两个命令的响应.
PySerial与Arduino或USB RS-232端口之间通常有多长时间的硬件握手?
我想在将数据表加载数据表之前将电子表格的所有单元格格式化为文本.这是我正在使用的示例代码
StringBuilder sbitems = new StringBuilder();
sbitems.Append(@"select * from Items");
SqlDataAdapter daitems = null;
DataSet dsitems = null;
daitems = new SqlDataAdapter(sbitems.ToString(), constate);
daitems.SelectCommand.CommandTimeout = 0;
dsitems = new DataSet("Items");
daitems.Fill(dsitems);
app.Workbook.Worksheets.Add("Items").Cells["A1"].LoadFromDataTable(dsitems.Tables[0], true);
Excel.ExcelWorksheet worksheet2 = workBook.Worksheets["Items"];
using (var rngitems = worksheet2.Cells["A1:BH1"])//Giving colour to header
{
rngitems.Style.Font.Bold = true;
rngitems.Style.Fill.PatternType = ExcelFillStyle.Solid;
rngitems.Style.Fill.BackgroundColor.SetColor(Color.Yellow);
rngitems.Style.Font.Size = 11;
rngitems.AutoFitColumns();
}
worksheet2.Cells["A1:BH1"].AutoFitColumns();
worksheet2.Cells["A1:BH1"].Style.Font.Bold = true;
app.SaveAs(new System.IO.FileInfo(@"D:\ItemsData\testfileexcelnew.xlsx"));
Run Code Online (Sandbox Code Playgroud) 当我将整个表写入excel工作表时,我知道一次使用整个Range,而不是写入单个单元格.但是,有没有办法指定格式,因为我正在填充我要导出到Excel的数组?
这就是我现在所做的:
object MissingValue = System.Reflection.Missing.Value;
Excel.Application excel = new Excel.Application();
int rows = 5;
int cols = 5;
int someVal;
Excel.Worksheet sheet = (Excel.Worksheet)excel.Workbooks.Add(MissingValue).Sheets[1];
Excel.Range range = sheet.Range("A1", sheet.Cells(rows,cols));
object[,] rangeData = new object[rows,cols];
for(int r = 0; r < rows; r++)
{
for(int c = 0; c < cols; c++)
{
someVal = r + c;
rangeData[r,c] = someVal.ToString();
}
}
range.set_Value(MissingValue, rangeData);
Run Code Online (Sandbox Code Playgroud)
现在假设我希望将这些数字中的一些格式化为百分比.我知道我可以逐个单元地返回并更改格式,但这似乎打败了使用单个Range.set_Value()调用的整个目的.我可以使我的rangeData [,]结构包含格式化信息,这样当我调用set_Value()时,单元格的格式是我想要的吗?
为了澄清,我知道我可以设置整个Excel.Range对象的格式.我想要的是为内部循环中指定的每个单元格指定不同的格式.
在采访中,采访者向我询问..我有一个代码,写在try和catch块之类的
try
{
//code line 1
//code line 2
//code line3 -- if error occur on this line then did not go in the catch block
//code line 4
//code line 5
}
catch()
{
throw
}
Run Code Online (Sandbox Code Playgroud)
假设我们在代码行3上出现错误,那么这不会进入catch块但是如果我在除了第3行之外的任何其他行上都有错误它会进入catch块
这是否可能,如果在特定行上发生错误,那么它不会进入catch块?
我在“ added_parts = new_part_set[(new_part_set["duplicate"] == False) & (new_part_set["version"] == "target")]"**行得到E712的flake 8错误
以下是我们用于电子表格比较的代码片段
source_df = pd.read_excel(self.source, sheet).fillna('NA')
target_df = pd.read_excel(self.target, sheet).fillna('NA')
file_path = os.path.dirname(self.source)
column_list = source_df.columns.tolist()
source_df['version'] = "source"
target_df['version'] = "target"
source_df.sort_values(by=unique_col)
source_df = source_df.reindex()
target_df.sort_values(by=unique_col)
target_df = target_df.reindex()
# full_set = pd.concat([source_df, target_df], ignore_index=True)
diff_panel = pd.concat([source_df, target_df],
axis='columns', keys=['df1', 'df2'], join='outer', sort=False)
diff_output = diff_panel.apply(self.__report_diff, axis=0)
diff_output['has_change'] = diff_output.apply(self.__has_change)
full_set = pd.concat([source_df, target_df], ignore_index=True)
changes = full_set.drop_duplicates(subset=column_list, keep='last')
dupe_records = changes.set_index(unique_col).index.unique()
changes['duplicate'] = changes[unique_col].isin(dupe_records)
removed_parts = changes[(changes["duplicate"] …Run Code Online (Sandbox Code Playgroud) c# ×6
excel ×3
python ×2
.net ×1
android ×1
arduino ×1
cell ×1
epplus ×1
flake8 ×1
gantt-chart ×1
interop ×1
line-breaks ×1
oledb ×1
openxml ×1
out ×1
pandas ×1
pep8 ×1
process ×1
pyserial ×1
reference ×1
return ×1
scheduling ×1
serial-port ×1
spreadsheet ×1
windows ×1