엑셀 워크 시트 (.xls)가 있습니다. SQL 스크립트로 변환해야합니다. 단일 Excel 워크 시트는 여러 테이블로 구성됩니다. 결과 스크립트에는 여러 개의 create table 및 insert 문이 있어야합니다. http://www.sqlconverter.com/과 같은 다양한 도구를 사용해 보았지만 적절한 해결책을 얻을 수 없습니다. 내가 할 수있는 다른 방법?엑셀 워크 시트를 SQL 스크립트로 변환합니다.
답변
가져 오기 마법사를 사용하면 원하는 것보다 더 복잡한 솔루션을 사용했기 때문에 데이터를로드해야한다는 의견을 보았습니다. ,
먼저 각 시트에 SAVE AS를하고 CSV 파일로 변환 :
당신은 BULK INSERT
을 시도 할 수 있습니다. 가져올 각 시트마다 하나의 CSV 파일이 있어야합니다.
다음으로 가져올 유사한 데이터 유형과 길이의 표를 만드십시오. 전형적인 Excel 셀은 VARCHAR (255)입니다 (구체적으로 말하면 NVARCHAR (255) 하지만이 솔루션에서는 유니 코드를 사용하지 않을 것입니다.) 당신의 엑셀 시트는 5 열이 있다면
그래서 :
CREATE TABLE Sheet1
(Column1 VARCHAR(255)
, Column2 VARCHAR(255)
, Column3 VARCHAR(255)
, Column4 VARCHAR(255)
, Column5 VARCHAR(255)
)
을 그런 다음 테이블은 네트워크 공유 또는 로컬 서버에/기계는 SQL에있는 파일이 제공에 대한 간단한 대량 삽입을 쓸 수 있습니다 실례입니다. 예를 들어, 컴퓨터에 파일이 있고 네트워크에서 서버로 푸시하려고했다면 SQL은 아래 스크립트의 C:\
이 서버가 아니라 서버에 있다고 생각합니다. 당신은 폴더를 공유해야하고이를 네트워크를 통해 액세스합니다 : \\MyMachineName\SharedFolder\Sheet1.csv
BULK INSERT dbo.Sheet1
FROM 'C:\LocalFolder\WhereTheFileIs\Sheet1.csv'
WITH (
FIELDTERMINATOR = ','
, ROWTERMINATOR = '\n'
)
이 그 테이블에 데이터 파일과 테이블에 존재하는 동일한 수의 열을 제공 받아야합니다.
꽤 아니지만 간단합니다. BULK INSERT
은 기본적이고 빠른 로딩을 시도한 진정한 방법입니다.
는 엑셀에서 그룹 삽입하는 간단한 방법이있다 : 데이터가 sepearate 열의 열 B, C 및 D에 있다면 간단히 만들 화학식 : = "& B1 &", ""값 (삽입 " ' "& C1 & '', ''& D1은 &는" ')
테이블 정의와 완전한 SQL 삽입 스크립트에 XLSX, CSV 또는 JSON에서 테이블 변환을 포함하여이를 수행 sqlizer.io 온라인 도구입니다.
SQLizer.io는 5,000 행 미만의 변환에 대해 무료이다. 데이터 –
http://www.convertcsv.com/csv-to-sql.htm –
이있다 vamsi krishna mysore 님의 작성자 : 1.apache apoi는 내가
package excelread;
import java.io.File;
import java.io.FileOutputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
public class ExcelRead
{
public static void main(String[] args) throws Exception
{
try
{
FileOutputStream output=new FileOutputStream("result.docx");
FileOutputStream output=new FileOutputStream("result.sql");//sql script in the script
FileOutputStream output=new FileOutputStream("result.xlxs");
FileOutputStream output=new FileOutputStream("result.csv");
XWPFDocument doc=new XWPFDocument();
XWPFParagraph para=doc.createParagraph();
para.setAlignment(ParagraphAlignment.CENTER);
XWPFRun pararun=para.createRun();
pararun.setBold(true);
pararun.setFontSize(20);
pararun.setText("Database Tables\n\n");
File f= new File("C:\\Users\\admin\\Desktop\\BUILDING_TB.xls");//file location where it is stored in the system
Workbook wb= Workbook.getWorkbook(f);
int sheets=wb.getNumberOfSheets();
for(int s1=0;s1<sheets;s1++)
{
System.out.println("for sheet"+s1);
Sheet s= wb.getSheet(s1);
String tbname=s.getName();
XWPFParagraph para1=doc.createParagraph();
para1.setAlignment(ParagraphAlignment.LEFT);
pararun=para1.createRun();
pararun.setText(tbname);
pararun.setFontSize(16);
pararun.setUnderline(UnderlinePatterns.WORDS);
int rows=s.getRows();
int cols=s.getColumns();
int indexrows=0;
int cols1=0;
int indexcols=0;
int pk=1000,dt=1000,cn=1000,ci=1000,dd=1000,n=1000,com=1000;
int ava=0;
List <String> comments= new LinkedList <String>();
List <String> sequence= new LinkedList <String>();
List <String> cid= new LinkedList <String>();
String createQuery="create table " +tbname+"(";
System.out.println(rows+" "+cols);
for(int j=0;j<rows;j++) //TO AVOID EMPTY ROW AND COLUMNS
{
sequence.clear();
for(int i=0;i<cols;i++) //TO GET ONE ROW DETAILS
{
indexcols=0;
cols1=0;
Cell c=s.getCell(i,j);
sequence.add(c.getContents());
}
for(int i=0;i<cols;i++)
{
if(sequence.get(i)=="")
{
cols1= ++indexcols;
}
else
{
ava=1;
indexrows=j;
break;
}
}
if(ava==1)
break;
}
for(;indexcols<cols;indexcols++) //TO ARRANG DATA IN REQUIRED ORDER
{
if(sequence.get(indexcols).toLowerCase().contains("PK".toLowerCase()))
{
pk=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("Column_id".toLowerCase()))
{
ci=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("Column_Name".toLowerCase()))
{
cn=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("nullable".toLowerCase()))
{
n=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("Data_TYpe".toLowerCase()))
{
dt=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("Default".toLowerCase()))
{
dd=indexcols;
}
else if(sequence.get(indexcols).toLowerCase().contains("comments".toLowerCase()))
{
com=indexcols;
}
}
indexrows++;
int rows1=indexrows;
for(;indexrows<rows;indexrows++) //PREPARING QUERY(For excel rows which contain data)
{
indexcols=cols1;
for(;indexcols<cols;indexcols++) //for all columns
{
Cell c=s.getCell(indexcols, indexrows);
String item=c.getContents();
//adding Column name to query
if(indexcols==cn)
{ if(!(item.equals("")) && indexrows!=rows1)
createQuery =createQuery+" ,"+item;
else if(item.equals(""))
break;
else
createQuery =createQuery+" "+item;
}
//adding data type to query
if(indexcols==dt)
{
createQuery =createQuery+" "+item;
}
//adding data default to query
else if(indexcols==dd)
{
if(item=="")
continue;
else
createQuery =createQuery+" "+"default "+item;
}
//addig primary key constaint to query
else if(indexcols==pk)
{
if(item.equalsIgnoreCase("true"))
createQuery =createQuery+" "+"primary key";
else
createQuery =createQuery+" "+"";
}
//adding not null constraint to query
else if(indexcols==n)
{
if(item.equalsIgnoreCase("no"))
createQuery =createQuery+" "+"not null";
else
createQuery =createQuery+" "+"";
}
//adding comments
else if(indexcols==com)
{
if(item!="")
{
comments.add(item);
}
else
{
comments.add("comments empty");
}
}
else if(indexcols==ci)
{
if(item!=null)
{
cid.add(item);
}
}
}//column loop close
}//row looop close
createQuery=createQuery+")";
System.out.println(createQuery);
XWPFParagraph para2=doc.createParagraph();
para2.setAlignment(ParagraphAlignment.LEFT);
pararun=para2.createRun();
pararun.setFontSize(14);
pararun.setText(createQuery+";");
System.out.println("table created successfully");
}//sheets loop closse
doc.write(output); //writing data into ouptu file
output.close();
}//try block close
catch(Exception e)
{
System.out.println(e.toString());
}
}//main close
}//class close
- 1. 엑셀 워크 시트를 mvc.net에서 읽으십시오.
- 2. 엑셀 파일에서 기본 워크 시트를 선택하는 방법
- 3. 엑셀 시트를 선택하십시오.
- 4. 워크 시트를 하나의 엑셀 워크 북으로 가져 오기
- 5. 엑셀 시트를 양식에 넣으십시오.
- 6. 엑셀 시트를 숨기는 부분
- 7. 여러 엑셀 시트를 만드는 방법
- 8. 엑셀 스프레드 시트를 HTML로 변환
- 9. 엑셀 시트를 조작하기위한 파이썬 스크립트
- 10. 엑셀 시트를 읽는 이유는 무엇입니까?
- 11. html 표 자바 스크립트에서 시트를 엑셀
- 12. 기존 엑셀 파일에 새 시트를 추가하여 시트를 엑셀 시트로 가져 오기
- 13. PHP와 JSON을 자바 스크립트로 변환합니다.
- 14. 엑셀 워크 북 모의
- 15. 내가 계산을위한 엑셀 시트를 복사 엑셀 VBA에서 다음 코드를 사용
- 16. Excel 워크 시트를 데이터 테이블로 가져 오기
- 17. 기존 엑셀 워크 시트로 데이터 내보내기
- 18. 파이썬으로 URL의 데이터로 엑셀 시트를 만드는 방법
- 19. 유닉스 : 시트를 엑셀 파일 이름과 위치
- 20. 브라우저에서 엑셀 스프레드 시트를 다운로드하여 표시하는 방법
- 21. 엑셀 스프레드 시트를 엑세스로 연결하는 VBA
- 22. 엑셀 시트를 읽는 중 BiffException이 발생했습니다.
- 23. 아이폰 SDK에서 URL로 엑셀 시트를 읽으십시오
- 24. 파이썬에서 SSL로 엑셀 시트를 전자 메일로 보내기
- 25. 내 스크립트는 PHP5에서 엑셀 시트를 작성하고 PHP5
- 26. 엑셀 시트를 MySQL로 가져 오기위한 일괄 스크립트
- 27. vbscript, 워크 시트에 8.0 암호를 엑셀
- 28. 정렬 순서가 역순으로 생성 된 시간을 기준으로/엑셀 시트를 반대로
- 29. 워크 시트를 가져 오는 방법
- 30. Excel 워크 시트를 AS400으로 업로드
AFAIK MS SQL 서버 데이터베이스에 엑셀 시트를로드하는 데 몇 가지 기능을 제공하는이 프로젝트에 sused 파일 및 시스템 아파치 apoi에 추가되어야 사용되어야합니다 : HTTP : // support.microsoft.com/kb/321686 – muehlbau
내가 전에이 링크를 보았지만 매우 복잡하고 그것을 통과 할 수 없다. 나는 그것을위한 간단한 해결책이 필요하다. – user1402867