Hướng dẫn convert python to csharp - chuyển đổi python thành csharp

An online tool for developers to convert Python source code files to C#. Just select a [*.py] file for instant conversion to C#. No source code is sent to a remote server - the conversion takes place entirely in your browser so your source code is safe and private.

  • Python
  • C#
  • Pytocs
  • Community

Phone/Zalo/Telegram/WhatsApp: +84.933.913.122cách làm việc tập tin Python trong lập trình C#, Winform.

Youtube Channel: //www.youtube.com/c/CTutorialsTips

Buy me a cup of beer

       

BÀI VIẾT LIÊN QUAN

Đăng bởi: Thảo meo - Lượt xem: 300815:32:53, 10/10/2021EBOOK

Xin chào các bạn, bài viết hôm nay mình sẻ tiếp tục hướng dẫn các bạn cách làm việc tập tin Python trong lập trình C#, Winform.

Code python Read Excel:

import pandas, sys
uri_excel_path=sys.argv[1]
sys.stdout.reconfigure[encoding='utf-8']
excel_data_df = pandas.read_excel[uri_excel_path, sheet_name='data']
json_str = excel_data_df.to_json[orient='records']
print[json_str]

Ở code python này: dữ liệu chúng ta truyền vào là đường dẫn tập tin file excel

Và kết quả trả về là file json data.

Full source code C# run python:

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DemoReadExcel
{
    public partial class Form1 : Form
    {
        public Form1[]
        {
            InitializeComponent[];
        }

        private void btn_browse_Click[object sender, EventArgs e]
        {
            var dlg = new OpenFileDialog[];
            if[dlg.ShowDialog[] == DialogResult.OK]
            {
                txt_uri.Text = dlg.FileName;
            }
        }

        private void btn_readexcel_Click[object sender, EventArgs e]
        {
            var jData = ReadExcelFromPython[txt_uri.Text];
            var table = JsonConvert.DeserializeObject[jData];

            dataGridView1.DataSource = table;
        }

        public string ReadExcelFromPython[string url]
        {

            var command = $@"{Application.StartupPath}
eadexcel.py  ""{url}""";
            Process process = new Process[];
            ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo[];
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.CreateNoWindow = true;
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.FileName = @"C:Users
guyeAppDataLocalProgramsPythonPython39python.exe";
            startInfo.Arguments = $"{command}";
            startInfo.StandardOutputEncoding = Encoding.UTF8;
            process.StartInfo = startInfo;
            process.Start[];
            string output = process.StandardOutput.ReadToEnd[];
            process.WaitForExit[];

            return output;


        }
    }
}

Chi tiết bạn có thể xem video hướng dẫn step by step:

 

Thanks for watching!

pass unrar: laptrinhvb.net

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

Founder 1149 bài viết 9,762,281

NGUYỄN THẢO

Founder at LaptrinhVB.net at LaptrinhVB.net

★★★★★

♥ Tình yêu thương chẳng hề hư mất bao giờ. [Cr 13,4]

=========================================================================

My skills includes .NET[C#, VB.NET], DevExpress, Java, Android, PHP,

Python, Sqlserver, Mysql, Reactjs, Dart, Flutter, API services and lot more... Mysql, Reactjs, Dart, Flutter, API services and lot more...

Phone/Zalo/Telegram/WhatsApp: +84.933.913.122+84.933.913.122

Email: 

Facebook: //fb.com/Lewandowski28031988//fb.com/Lewandowski28031988

Youtube Channel: //www.youtube.com/c/CTutorialsTips

 

Buy me a cup of beer

       

=========================================================================

My skills includes .NET[C#, VB.NET], DevExpress, Java, Android, PHP,

Python, Sqlserver, Mysql, Reactjs, Dart, Flutter, API services and lot more...Thảo meo - Lượt xem: 3008 15:32:53, 10/10/2021EBOOK

Bài Viết Liên Quan

Chủ Đề