【Python开发】Excel的操作之——读取分分快三计划

作者:编程技术

 

View Code

View Code

除此以外小编使用的是bat批管理公事调用py文件,bat代码如下:

分分快三计划 1分分快三计划 2

1 @echo off
2 
3 echo 开始运行ExcelRead程序
4 echo
5 
6 python G:PycharmProjects【180817】ExcelOperationExcelRead.py
7 
8 pause

View Code

实践效果如下:

分分快三计划 3

下一步布置必要把读出来的数目按表排列………(未完待续卡塔尔

前几日优化代码:

分分快三计划 4分分快三计划 5

 1 def read_excel():
 2     workbook = xlrd.open_workbook(r'C:UserswxzDesktop2018年信用卡花费(Kevin).xlsx')
 3     sheet_name = workbook.sheet_names() # 获取所有sheet表名称
 4     sheet_length = sheet_name.__len__() # 获取sheet表长度
 5     print('已读取Excel所有sheet表名称:')
 6 
 7     sheet_num = 0
 8     for name in sheet_name:
 9         print(str([sheet_num])   ':'   name)
10         sheet_num = sheet_num   1
11 
12     while True:
13         sheet_index = int(input('n请输入需要打印的sheet表序号:'))
14         if sheet_index < sheet_length:
15             print('n正在打印《'   workbook.sheet_names()[sheet_index]   '》的内容……n')
16 
17             current_sheet = workbook.sheet_by_index(sheet_index)
18             nrows = current_sheet.nrows                             # 获取当前列表的行数
19 
20             for n in range(nrows):
21                 sheet_list = current_sheet.row_values(n)  # 读取的excelsheet无法修改(只读),添加list转换
22 
23                 # 整理数据表,建立表头,之后增加
24                 if n == 0: # 输出表头
25                     table = PrettyTable(sheet_list)
26                 else:      # 输出内容
27                     # 项目内容判断
28                     if sheet_list[1] == "":
29                         print('提示:第'   str(n)   '行未填入项目内容!')
30 
31                     # 金额内容判断
32                     if sheet_list[2] == "":
33                         print('提示:第'   str(n)   '行未填入金额!')
34 
35                     # 日期内容判断
36                     if sheet_list[3] == "":
37                         print('提示:第'   str(n)   '行未填入日期!')
38                     else:
39                         # 日期格式判断
40                         if type(sheet_list[3] == float) and type(sheet_list[3]) != str:   #时间转换
41                             datetime = xlrd.xldate_as_datetime(current_sheet.cell(n,3).value,workbook.datemode)
42                             sheet_list[3] = datetime.date()
43                         else:
44                             sheet_list[3] = ''
45                             print('提示:第'   str(n)   '行未正确填入日期,取消显示!')
46 
47                     table.add_row(sheet_list)
48 
49             print('')       # 空一行
50             print(table)    # 打印最终表格
51 
52             print('n共有'   str(nrows)   '行,已全部打印完毕n')
53             break;
54         else:
55             print('错误提示:sheet表序号超出最大长度,请重新输入')

View Code

运行结果如下,比前几日的雅观多了:

分分快三计划 6

 

分分快三计划 7分分快三计划 8

View Code

上边贴上自家本身的代码

读取excel数据的demo代码如下:

分分快三计划 9分分快三计划 10

 1 def read_excel_demo():
 2     # 打开文件
 3     workbook = xlrd.open_workbook(r'C:UserswxzDesktop2018年信用卡花费(Kevin).xlsx')
 4     # 获取所有sheet
 5     print('打印所有sheet表名称:',workbook.sheet_names())
 6     sheet1_name = workbook.sheet_names()[0]
 7     sheet2_name = workbook.sheet_names()[1]
 8     # print(sheet1_name)
 9 
10     # 根据sheet索引或者名称获取sheet内容
11     sheet1 = workbook.sheet_by_index(0)
12     # TODO 问题
13     # sheet2 = workbook.sheet_by_name('sheet1_name')
14     # print(sheet2)
15 
16     # sheet的名称,行数,列数
17     print(sheet1.name, sheet1.nrows, sheet1.ncols)
18 
19     # 获取整行和整列的值(数组)
20     rows = sheet1.row_values(0)
21     cols = sheet1.col_values(0)
22     print(rows)
23     print(cols)
24 
25     # 获取单元格内容
26     print(sheet1.cell(0, 0).value)
27     print(sheet1.cell_value(0, 0))
28     print(sheet1.row(0)[0].value)
29 
30     # 获取单元格内容的数据类型 ctype :  0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error
31     print(sheet1.cell(0, 0).ctype)
32 
33     # 获取日期
34     if sheet1.cell(1, 3).ctype == 3:
35         datetime = xlrd.xldate_as_datetime(sheet1.cell(1, 3).value, workbook.datemode)
36         print(datetime.date())

View Code

友好写的其实调用函数如下:

分分快三计划 11分分快三计划 12

 1 def read_excel():
 2     workbook = xlrd.open_workbook(r'C:UserswxzDesktop2018年信用卡花费(Kevin).xlsx')
 3     sheet_name = workbook.sheet_names() # 获取所有sheet表名称
 4     sheet_length = sheet_name.__len__() # 获取sheet表长度
 5     print('已读取Excel所有sheet表名称:')
 6 
 7     sheet_num = 0
 8     for name in sheet_name:
 9         print(str([sheet_num])   ':'   name)
10         sheet_num = sheet_num   1
11 
12     while True:
13         sheet_index = int(input('n请输入需要打印的sheet表序号:'))
14         if sheet_index < sheet_length:
15             print('n正在打印《'   workbook.sheet_names()[sheet_index]   '》的内容……n')
16 
17             current_sheet = workbook.sheet_by_index(sheet_index)
18             nrows = current_sheet.nrows
19             for n in range(nrows):
20                 print(current_sheet.row_values(n))
21 
22             print('n共有'   str(nrows)   '行,已全部打印完毕n')
23             break;
24         else:
25             print('错误提示:sheet表序号超出最大长度,请重新输入')
26 
27 if __name__ == '__main__':
28     read_excel()

View Code

View Code

查询内部存款和储蓄器和CPU:

最首要思路仿照效法这篇博客的原委,把地点贴上:

 

分分快三计划 13分分快三计划 14

@echo off
C:WindowsMicrosoft.NETFrameworkv2.0.50727aspnet_regiis.exe -pdf "connectionStrings" "D:Program FilesMicrosoft.NET Pet Shop 4.0Web"
PAUSE

分分快三计划 15分分快三计划 16

 

 1 ConnectionOptions Conn = new ConnectionOptions();
 2             Conn.Username = userName; //设定用户的口令
 3             Conn.Password = pwd;
 4             Ms = new ManagementScope("\\"   ip   "\root\cimv2", Conn);
 5             Ms.Connect();
 6  ManagementClass processClass = new ManagementClass(Ms, new ManagementPath("Win32_Process"), null);
 7             //获得用来提供参数的对象
 8             ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
 9             //设定命令行参数
10                 inParams["CommandLine"] = path;// @"需要启动的进程路径";
11                 //执行程序
12             ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
@echo off
C:WindowsMicrosoft.NETFrameworkv2.0.50727aspnet_regiis.exe -pef "connectionStrings" "D:Program FilesMicrosoft.NET Pet Shop 4.0Web"
PAUSE

View Code

直白将语句拷贝到.BAT文件中,D:Program FilesMicrosoft.NET Pet Shop 4.0Web 为相应的web.config所在的门道,只好在黄金时代台Computer上操作,不然不可逆!

 1 var capacity = 0.0;
 2    var free = 0.0;
 3   var cpu = 0.0;
 4  // 2048
 5    foreach (var o in searcher1.Get())
 6capacity  = (double)Convert.ToUInt64(o[PROPERTY_CAPACITY]) / (double)(1024 * 1024);
 7                         foreach (var o in searcher2.Get())
 8                             free  = (double)Convert.ToUInt64(o[PROPERTY_AVAILABLE_BYTES]) / (double)(1024 * 1024);
 9                         foreach (var o in searcher3.Get())
10                         {
11                             if (o["LoadPercentage"] != null)
12                             {
13                                 cpu = long.Parse(o["LoadPercentage"].ToString());
14                             }
15                             else {
16                                 cpu = 0;
17                             }
18                         }

加密前:

View Code

现实的能够参照petshop源码程序。

分分快三计划 17分分快三计划 18

DecryptWebConfig.bat解密批管理代码:

View Code

 

C#兑现对长间距服务器的内部存款和储蓄器和CPU监察和控制小记

  <connectionStrings>
    <add name="SQLProfileConnString" connectionString="server=(local);user id=mspetshop;password=pass@word1;database=MSPetShop4Profile;min pool size=4;max pool size=4;packet size=3072"
    providerName="System.Data.SqlClient" />
    <add name="SQLMembershipConnString" connectionString="server=(local);user id=mspetshop;password=pass@word1;database=MSPetShop4Services;min pool size=4;max pool size=4;packet size=3072"
    providerName="System.Data.SqlClient" />
    <add name="SQLConnString1" connectionString="server=(local);user id=mspetshop;password=pass@word1;database=MSPetShop4;min pool size=4;max pool size=4;packet size=3072"
    providerName="System.Data.SqlClient" />
    <add name="SQLConnString2" connectionString="server=(local);user id=mspetshop;password=pass@word1;database=MSPetShop4;min pool size=4;max pool size=4;packet size=1024"
    providerName="System.Data.SqlClient" />
    <add name="SQLConnString3" connectionString="server=(local);user id=mspetshop;password=pass@word1;database=MSPetShop4Orders;min pool size=4;max pool size=4;packet size=1024"
    providerName="System.Data.SqlClient" />
    <add name="OraProfileConnString" connectionString="Data Source=localhost;user id=MSPETSHOPPROFILE;password=pass@word1;min pool size=4;max pool size=4"
    providerName="System.Data.OracleClient" />
    <add name="OraMembershipConnString" connectionString="Data Source=localhost;user id=MSPETSHOPMEMBERSHIP;password=pass@word1;min pool size=4;max pool size=4"
    providerName="System.Data.OracleClient" />
    <add name="OraConnString1" connectionString="Data Source=localhost;user id=MSPETSHOP;password=pass@word1;min pool size=4;max pool size=4"
    providerName="System.Data.OracleClient" />
    <add name="OraConnString2" connectionString="Data Source=localhost;user id=MSPETSHOP;password=pass@word1;min pool size=4;max pool size=4"
    providerName="System.Data.OracleClient" />
    <add name="OraConnString3" connectionString="Data Source=localhost;user id=MSPETSHOPORDERS;password=pass@word1;min pool size=4;max pool size=4"
    providerName="System.Data.OracleClient" />
  </connectionStrings>

一而再一连远程服务器示例代码:

View Code

 一时就到那时候了。

 

具体查询比如:

View Code

比方远程重启有个别进程(部分演示代码卡塔 尔(英语:State of Qatar):

  <connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
      xmlns="http://www.w3.org/2001/04/xmlenc#">
      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
      <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
        <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
          <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
          <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
            <KeyName>Rsa Key</KeyName>
          </KeyInfo>
          <CipherData>
            <CipherValue>toBlOJmJmZ/3SYJaltdhQA/RfrSAwf633228VBzG0ZUeTq2jsJksoxQID0GVozH3AQbfbIVoXdg0KsPgLpT3a Xi5KGvWwyurrNqt0cPBCvWoBRtQLoc5ni87hbqDFaxSTrS9xX2kIpeC91QE1lA l7Kk9e48YaJxPw82ZnzgUM=</CipherValue>
          </CipherData>
        </EncryptedKey>
      </KeyInfo>
      <CipherData>
        <CipherValue>yFoUrcd3MH3tsgquIezF6sfaI2rZKlxYDRX58m0jdgKTNK1hp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7iLo16s5L8qVCIqIXbW2VFLeTZ8BSvTYJ /v8qBtIke4gd4YfEUshzi E7KJuikaXMjaiOq6RwR7g7 SEwg3JMhJMh1CIJ75F6VgQloVOD4ojwAK12W6MLH86bP RlJX4awAY8E9MmFhU5c8EBj4peHP3RPFK0whKwfxMdlafH9VeXXonh6V7BEz913x3gwN8sg4LT1eyIHFqHT3j5EpnTyFt5x XvmRPf993lOFmIp76Oehn6rShd2dQ91z7OvobGvvpUf2Ala9K6hLAk07HRVXJJ3mZeXzfUX8VBNQzfytikX/ZF0vyv3wOiavPEsaDvBHg39JMJlfU2MInJpCMYPsK6yyt5mWXaPppFX0Bg0 LLG5L3dz sbwGOwPrtjJh3TwD3keLO/du9dwkzLPfwume3RsOjws2vgTbz2JN7GFQOiPooDoOWvCzNUkZBzUa4Mb5qGH2y7jST2sT/X0 bY shakavxUz0woCt1QfCvRq1lipmPIohRyj Xw QvQQkDSDSiZjE/ZXda25IHUO0tEJhAoajW8FYEcdECPhCSGptcizTPsmhUkS1BC9qykqG6vpgZ6C C8=</CipherValue>
      </CipherData>
    </EncryptedData>
  </connectionStrings>

1、  重要行使到的组件有System.Management.dll

加密后:

分分快三计划 19分分快三计划 20

EncryptWebConfig.bat加密批管理代码:

闭馆有些进度:

分分快三计划 21分分快三计划 22

举例说查询全数进度 :tasklist /S ip /U 客商名 /P 密码

分分快三计划 23分分快三计划 24

taskkill  /S ip /U客商名/P 密码  /IM 要求关闭的长河名

分分快三计划 25分分快三计划 26

 1 public delegate void DelReadStdOutput(string result);
 2         public delegate void DelReadErrOutput(string result);
 3         public event DelReadStdOutput ReadStdOutput;
 4         public event DelReadErrOutput ReadErrOutput;
 5 /// <summary>
 6         /// 注册事件
 7         /// </summary>
 8         private void Init()
 9         {
10             ReadStdOutput  = new DelReadStdOutput(ReadStdOutputAction);
11             ReadErrOutput  = new DelReadErrOutput(ReadErrOutputAction);
12 
13         }
14 //----------------------部分实现代码==================
15 using (p = new Process())
16                 {
17  
18                     //pause --  停止
19                     p.StartInfo.FileName = fileName;
20                  
21                     p.StartInfo.UseShellExecute = false;
22                     p.StartInfo.CreateNoWindow = true;
23 
24                     p.StartInfo.RedirectStandardError = true;
25                     p.StartInfo.RedirectStandardInput = true;
26                     p.StartInfo.RedirectStandardOutput = true;
27                     p.EnableRaisingEvents = true;
28                     p.Exited  = new EventHandler(p_Exited);
29                     p.ErrorDataReceived  = new DataReceivedEventHandler(p_ErrorDataReceived);
30                     p.OutputDataReceived  = new DataReceivedEventHandler(p_OutputDataReceived);
31 
32                     p.Start();
33                     //读取输出:
34                     p.BeginErrorReadLine();
35                     p.BeginOutputReadLine();
36                     p.WaitForExit();
37                 }
38 
39 
40 void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
41         {
42             this.lab_tips.Text = "开始读取数据...读取时间可能有点长,请耐心等待!";
43             if (e.Data != null)
44             {
45                 this.Invoke(ReadStdOutput, new object[] { e.Data });
46             }
47 }
48 // 读取进程信息:
49 public void ReadStdOutputAction(string s)
50         {
51         
52             if (num > 1)
53             {
54                 budiler.AppendLine(s);
55             }
56             this.textBox1.Text = budiler.ToString();
57             num  ;
58         }

2、  主要类为 :ManagementScope

分分快三计划 27分分快三计划 28

 1 private const string PROPERTY_CAPACITY = "Capacity";
 2         private const string PROPERTY_AVAILABLE_BYTES = "AvailableBytes";
 3         private const string PROPERTY_PROCESS_ID = "ProcessId";
 4         private const string PROPERTY_PROCESS_NAME = "Name";
 5         private const string PROPERTY_WORKING_SET_SIZE = "WorkingSetSize";
 6 
 7 
 8 ConnectionOptions Conn = new ConnectionOptions();
 9                 //设定用于WMI连接操作的用户名   
10                 Conn.Username = "用户名";
11                 //设定用户的口令
12                 Conn.Password = "密码";
13              ManagementScope   Ms = new         ManagementScope("\\ip\root\cimv2", Conn);
14                 Ms.Connect();

Other、能够用程序操作批管理文件(.bat)来查询进程或然是停业进程:

意气风发对演示代码:

1 var query1 = new SelectQuery("SELECT * FROM Win32_PhysicalMemory");
2  var query2 = new SelectQuery("SELECT * FROM Win32_PerfRawData_PerfOS_Memory");
3   var query3 = new SelectQuery("SELECT * FROM Win32_Processor");
4  var query4 = new SelectQuery("SELECT * FROM Win32_Process");
5 
6  var searcher1 = new ManagementObjectSearcher(Ms, query1);
7  var searcher2 = new ManagementObjectSearcher(Ms, query2);
8 var searcher3 = new ManagementObjectSearcher(Ms, query3);
9 var searcher4 = new ManagementObjectSearcher(Ms, query4);

本文由分分快三计划发布,转载请注明来源

关键词: 分分快三计划 C# ASP.NET .NET技术