C# 根据EXCEL自动生成oracle建表语句
Excel示例
支持多表生成,多加几个sheet即可
- 生成效果
直接放码
using Microsoft.Office.Interop.Excel;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;namespace SQLCreate
{internal class Program{public class TableModel{public string tableName;public string tableCommit;public List<string> chName;public List<string> enName;public List<string> type;public List<string> commit;public TableModel(){chName = new List<string>();enName = new List<string>(); type = new List<string>();commit = new List<string>();}}static void Main(string[] args){string excelPath = "./test.xlsx";List<TableModel> tables = ReadFromExcel(excelPath);OutputTxt(tables);}public static void OutputTxt(List<TableModel> tables){foreach (var item in tables){string str = $"CREATE table {item.tableName}\n";str += "(\n";for (int i = 0; i < item.enName.Count; i++){str += $"{item.enName[i]} {item.type[i]},\n";}str += ");\n";str += $"comment on table {item.tableName} is '{item.tableCommit}';\n";for (int i = 0; i < item.enName.Count; i++){str += $"comment on table {item.tableName}.{item.enName[i]} is '{item.commit[i]}';\n";}OutputFile($"./result_{DateTime.Now.ToString("yyyymm")}.txt", str);}}public static void OutputFile(string strFilePath, string strContent){StreamWriter swOut = new StreamWriter(strFilePath, true, Encoding.Default);swOut.WriteLine(strContent);swOut.Flush();swOut.Close();}public static List<TableModel> ReadFromExcel(string filePath){#region xls//HSSFWorkbook = new HSSFWorkbook(fs);# endregionFileStream fs = File.OpenRead(filePath);XSSFWorkbook wk = new XSSFWorkbook(fs);fs.Close();List<TableModel> tables = new List<TableModel>();for (int i = 0; i < wk.NumberOfSheets; i++){TableModel table = new TableModel();ISheet sheet = wk.GetSheetAt(i);string[] title = sheet.GetRow(0).GetCell(0).ToString().Split(' ');table.tableName = title[1];table.tableCommit = title[0];for (int j = 2; j <= sheet.LastRowNum; j++){IRow row = sheet.GetRow(j); if (row != null){table.chName.Add(row.GetCell(0).ToString());table.enName.Add(row.GetCell(1).ToString());table.type.Add(row.GetCell(2).ToString());table.commit.Add(row.GetCell(3).ToString());}}tables.Add(table);}return tables;}}
}
C# 根据EXCEL自动生成oracle建表语句相关推荐
- Excel自动生成sql建表语句
ETL开发中重新整理很多表结构,写建表语句又是一件头疼的事情,干脆借鉴网友的代码,自己写了一个自动生成建表sql的模板. 模板下载:http://download.csdn.net/detail/en ...
- mysql json建表_json数据自动生成MySQL建表语句
#_*_coding:utf-8_*_ #author: cike #date: 18-9-13 import pymysql.cursors connection = pymysql.connect ...
- 自动获取mysql建表语句_脚本工具---自动解析mysql建表语句,生成sqlalchemy表对象声明...
常规建表语句: CREATE TABLE `test_table` ( `id` int(11) NOT NULL, `name` char(64) NOT NULL, `password` char ...
- python读取excel生成mysql建表语句_python读取excel文件并自动在mysql中建表导数据
""" 根据excel在mysql中建表(表名为文件名,字段为csv中的header,默认所有字段为varchar,如需更改,在数据库中更改即可),并插入数据 " ...
- excel自动生成舒尔特表_EXCEL自动生成的PPT
因为经常要做周报.月报PPT,每次重复的的操作效率很低,这里整理了一套可以自动生成PPT的办法. 首先,大概思路是这样的.周报.月报这类经营分析类PPT一般都是由表格.图表以及分析文字组成的,整体结构 ...
- excel自动生成舒尔特表_财务总监:超完美Excel全套账财务系统,自动生成报表,收好喽...
对于很多初学会计的小伙伴来说,很多账务不知该如何处理,三大会计报表也不知道该怎么做.或者是新手会计处理账务经常熬夜加班. 今天,小编给大家分享一套超级实用的Excel全套账财务系统,可以自动生成三大财 ...
- oracle建表语句string,编程式Mybatis获取oracle表创建表语句
写在前面 Mybatis之前使用过一段时间,当然只是粗糙地使用,而且配合Spring有一部分Mybatis管理的内容都交给了Spring,加上一段时间没用到又开始忘了,刚好今天碰到一个要求,Oracl ...
- SpringBoot自动运行sql建表语句
1.在Resources下添加建表的sql语句 2.配置文件 application.yml spring:datasource:username: rootpassword: adminurl: j ...
- 1.python 根据 oracle字段名和类型 生成 hive建表语句
一.问题 遇到一个场景,要根据oracle表结构创建hive表. 本来想写一个根据oracle信息和表名自动在hive中创建表的脚本.如果在集群运行,python操作oracle的cx_Oracle在 ...
- Quartz的oracle建表语句
建表语句 其中schedule_job是手动新增的,用于界面增删改查 CREATE TABLE schedule_job (id int NOT NULL,job_id VARCHAR2(255) D ...
最新文章
- libevent多线程使用bufferevent的那些事
- uva 10161 Ant on a Chessboard 蛇形矩阵 简单数学题
- P5540-[BalkanOI2011]timeismoney|最小乘积生成树【最小生成树,凸壳】
- .NEt中的继承、聚合和组合
- caffe模型文件解析_「机器学习」截取caffe模型中的某层
- opencv 轮廓层次结构
- MFC编码注意(2)
- oracle Ebs database clone (no apps clone)
- GDB简单调试linux内核与模块的方法
- 类似Windows开始菜单的右键菜单
- 思考伯努利试验的两种组合思想
- ath9k usb wifi 网卡驱动浅析
- 基于 Creator 3.0 的 3D 换装
- 蚂蚁森林自动收能量之AutoJs实现
- 【毕设教程】单片机如何运行SD卡里的程序
- KKT(Karush-Kuhn-Tucher)条件
- 翻翻git之---不靠画全靠“演”,好看的自定义TextView translucent-android
- 小米电视更换默认桌面和优化
- 《机器学习》赵卫东学习笔记 第13章推荐系统(课后习题及答案)
- Android WebView 录音