node读取excel

//生成sql‘


const mysqlx = require("@mysql/xdevapi");

let xlsx = require('node-xlsx');
let sheets = xlsx.parse('G:\\data.xlsx');

item_data();


async function item_data()
{
   sheets.forEach(function(sheet)
  {
    let data = sheet.data;

    //截取有效数字
    data = data.slice(0, 1);

    //去除undefined
    for (let i = data.length - 1; i >= 0; i--) {
      if (data[i][0] === undefined) {
        data.splice(i, 1);
      }
    }

    console.log(data.length);

    data.map(p =>
    {
      data = "'" + p.join("', '") + "'";
      let names = ['name', 'sex', 'age', 'complain', 'fever', 'temperate', 'cough', 'expectoration', 'pharyngalgia', 'dry_pharynx', 'myalgia', 'tired', 'weak', 'chest', 'short_of_breath', 'diarrhea', 'dyspnea', 'headache', 'diabetes', 'coronary', 'hypertesion', 'chronic_obstructive_pulmonary_disease', 'hepatopathy_history', 'nephroma_history', 'tuberculosis_history', 'disease_time', 'visit_time', 'time_space', 'diagnosis_time', 'wuhan_live_history', 'patient_community_live_history', 'wuhan_people_contach_history', 'patient_community_respiratory_symptoms', 'cluster_onset', 'virus_patient_contact_history', 'no_contact_history', 'incubation_period', 'double_lungs', 'one_lungs', 'lesions_location', 'ct_no_exception', 'pleural_effussion', 'real_change', 'spot_like_shadow', 'class_milling', 'shadow_of_infiltration', 'cable_shadow', 'checkout_date', 'WBC', 'RBC', 'HB_or_HGB', 'PLT', 'NEUT_OR_N', 'percentage_NEUT_OR_N', 'LY', 'percentage_LY', 'M_OR_MONO', 'PERCENTAGE_M_OR_MONO', 'E', 'PERCENTAGE_E', 'B', 'PERCENTAGE_B', 'CRP', 'ESR', 'PCT', 'CK_MB', 'oxygen_concentration', 'oxygen_number', 'PH', 'PaO2', 'SaO2', 'PCO2', 'Lac', 'GPT_OR_ALT', 'GOT_OR_AST', 'LDH', 'severity_of_disease', 'remark', 'photo_logging', 'mutiple'];

      str_name = names.join(",");

      const sql = `insert into dicom.pest_data2(${str_name}) values(${data}) ;`;
      console.log(sql);
    })
  })
};


async function insertData(data)
{
  data = "'" + data.join("', '") + "'";

  const session = await mysqlx.getSession
  ({
    user: 'root',
    password: '123456',
    host: 'localhost',
    port: '33060'
  });

  let names = ['name', 'sex', 'age', 'complain', 'fever', 'temperate', 'cough', 'expectoration', 'pharyngalgia', 'dry_pharynx', 'myalgia', 'tired', 'weak', 'chest', 'short_of_breath', 'diarrhea', 'dyspnea', 'headache', 'diabetes', 'coronary', 'hypertesion', 'chronic_obstructive_pulmonary_disease', 'hepatopathy_history', 'nephroma_history', 'tuberculosis_history', 'disease_time', 'visit_time', 'time_space', 'diagnosis_time', 'wuhan_live_history', 'patient_community_live_history', 'wuhan_people_contach_history', 'patient_community_respiratory_symptoms', 'cluster_onset', 'virus_patient_contact_history', 'no_contact_history', 'incubation_period', 'double_lungs', 'one_lungs', 'lesions_location', 'ct_no_exception', 'pleural_effussion', 'real_change', 'spot_like_shadow', 'class_milling', 'shadow_of_infiltration', 'cable_shadow', 'checkout_date', 'WBC', 'RBC', 'HB_or_HGB', 'PLT', 'NEUT_OR_N', 'percentage_NEUT_OR_N', 'LY', 'percentage_LY', 'M_OR_MONO', 'PERCENTAGE_M_OR_MONO', 'E', 'PERCENTAGE_E', 'B', 'PERCENTAGE_B', 'CRP', 'ESR', 'PCT', 'CK_MB', 'oxygen_concentration', 'oxygen_number', 'PH', 'PaO2', 'SaO2', 'PCO2', 'Lac', 'GPT_OR_ALT', 'GOT_OR_AST', 'LDH', 'severity_of_disease', 'remark', 'photo_logging', 'mutiple'];

  str_name = names.join(",");

  const sql = `insert into dicom.pest_data2(${str_name}) values(${data})`;

  console.log(sql);

  await session.sql(sql).execute(r => console.log(r)).catch(e=>console.log(e));

  session.close();

  return 1;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值