小编Mat*_*len的帖子

如何在C#中使用oledb仅上传非空行的Excel电子表格?

我正在使用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# oledb excel

9
推荐指数
3
解决办法
2万
查看次数

监视文件或目录中的更改?

在Android中,如何监视其他人(app,internet,bluetooth,dll)对文件或目录所做的更改

android

9
推荐指数
1
解决办法
9543
查看次数

C#out参数vs返回

所以我是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 …

c# return reference out

9
推荐指数
2
解决办法
7399
查看次数

如何计算循环调度的平均等待时间?

鉴于此表: 在此输入图像描述

那些是时间线(时间片= 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:此问题还涉及优先级算法作为辅助练习,请忽略循环算法的优先级列

scheduling process gantt-chart

9
推荐指数
2
解决办法
7万
查看次数

如何在OPENXML电子表格单元格中插入换行符?

我目前使用这样的东西在单元格中插入内联字符串:

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)

c# spreadsheet line-breaks cell openxml

8
推荐指数
2
解决办法
1万
查看次数

PySerial没有和Arduino说话

我已经编写了一些代码来模拟我正在使用的一些硬件并将其上传到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命令的响应结束时发回.

超级终端配置:

超级终端中的COM4配置

编辑

我发现如果我将超时增加到10秒并sp.readline()在发送任何内容之前添加一个,那么我会得到对这两个命令的响应.

PySerial与Arduino或USB RS-232端口之间通常有多长时间的硬件握手?

python windows serial-port arduino pyserial

8
推荐指数
1
解决办法
8067
查看次数

使用EPPlus我想在电子表格中将所有单元格格式化为TEXT

我想在将数据表加载数据表之前将电子表格的所有单元格格式化为文本.这是我正在使用的示例代码

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)

c# excel epplus

8
推荐指数
1
解决办法
1万
查看次数

如何使用Excel.Range.set_Value()指定单个单元格的格式

当我将整个表写入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对象的格式.我想要的是为内部循环中指定的每个单元格指定不同的格式.

.net c# excel interop

7
推荐指数
1
解决办法
1万
查看次数

On catch catch块没有调用

在采访中,采访者向我询问..我有一个代码,写在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块?

c#

7
推荐指数
1
解决办法
236
查看次数

如何修复pandas数据帧中的flake 8错误“E712与False的比较应该是'if cond is False:'或'if not cond:'”

我在“ added_pa​​rts = 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)

python pep8 pandas flake8

7
推荐指数
1
解决办法
1385
查看次数