如何使用 SQL Developer 中的 SQL Worksheet 插入,更新和删除数据

如何使用 SQL Developer 中的 SQL Worksheet 插入,更新和删除数据,第1张

需要有可执行的.sql文件作为执行脚本,然后需要按如下方法: 1、登录pl/sql。 2、打开.sql文件。 3、复制.sql文件中的内容。 4、打开pl/sql中的“新建”——"SQL窗口"。 5、将复制的内容粘贴到页面空白处。然后点击“齿轮”状的执行按钮。

using System

using System.IO

using Excel

namespace Kits.Excel

{

public class ExcelTools

{

/// <summary>

/// 导出到EXCEL表

/// </summary>

private static void toExcel(string FileName, string SheetName, System.Data.DataTable dt)

{

ApplicationClass myExcel = new ApplicationClass()

Worksheet worksheet = null

string curPath = Directory.GetParent(FileName).FullName

if(!Directory.Exists(curPath))

{

Directory.CreateDirectory(curPath)

}

if (File.Exists(FileName))

{

try

{

File.Delete(FileName)

}

catch

{

throw new Exception("文件 *** 作出错,可能正在运行当前的EXCEL文件!")

}

}

try

{

object missing = System.Reflection.Missing.Value

myExcel.Workbooks.Add(missing)

worksheet = (Worksheet)myExcel.ActiveSheet

worksheet.Name = SheetName

myExcel.Visible = false

int iRows = dt.Rows.Count

int iCol = dt.Columns.Count

worksheet.get_Range( worksheet.Cells[1, 1], worksheet.Cells[ iRows+1, iCol] ).NumberFormatLocal = "@"

for( int i=0i<iColi++)

{

worksheet.Cells[1,i+1] = dt.Columns[i].ToString()

}

int size = iRows / 1000

int page = 0

string[,] rows = null

for(int i=0i<iRows)

{

if(page<size)

{

rows = new string[1000,iCol]

for(int count=0count<1000count++)

{

for(int j=0j<iColj++)

{

rows[count,j] = dt.DefaultView[i][j].ToString()

}

i++

}

worksheet.get_Range(worksheet.Cells[page * 1000 + 2, 1], worksheet.Cells[ page * 1000 + 1001, iCol]).Value2 = rows

page++

}

else

{

int left = iRows % 1000

rows = new string[left,iCol]

for(int count=0count<leftcount++)

{

for(int j=0j<iColj++)

{

rows[count,j] = dt.DefaultView[i][j].ToString()

}

i++

}

worksheet.get_Range(worksheet.Cells[iRows+2-left, 1], worksheet.Cells[ iRows+1, iCol]).Value2 = rows

}

}

worksheet.SaveAs( FileName, missing, missing, missing, missing, missing, missing, missing, missing, missing)

}

catch(Exception ex)

{

throw new Exception(ex.Message)

}

finally

{

myExcel.Workbooks.Close()

myExcel.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet)

System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel)

worksheet = null

myExcel = null

GC.Collect()

}

}

/// <summary>

/// 因为调用EXCEL后,结束时EXCEL进程并没有立即KILL,用这个方法调用可以KILL掉EXCEL

/// </summary>

public static void callToExcel(string FileName, string SheetName, System.Data.DataTable dt)

{

toExcel(FileName, SheetName, dt)

GC.Collect()

}

}

}

需要添加一个引用Excel


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11944317.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存