NPOI匯出和匯入Excel,Word和PDF
Models資料夾
NPOIModel.cs
namespace NPOItest.Models
{
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
public partial class NPOIModel : DbContext
{
public NPOIModel()
: base("name=NPOIModel")
{
Database.SetInitializer(new InitDatabase());
}
public virtual DbSet<Account> Account { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
}
}
}
InitDatabase.cs
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace NPOItest.Models
{
public class InitDatabase : DropCreateDatabaseAlways<NPOIModel>
{
protected override void Seed(NPOItest.Models.NPOIModel context)
{
Account acc1 = new Account { Username = "admin", Password = "admin" , Name = "Kevin", Sex = "Man", Email = "[email protected]", Company = "XXX_NO.1", Position = "R&D", Phone = "0000-0000" };
Account acc2 = new Account { Username = "user", Password = "user", Name = "Durant", Sex = "Female", Email = "[email protected]", Company = "AAA_NO.2", Position = "CEO", Phone = "0000-1111" };
context.Account.Add(acc1);
context.Account.Add(acc2);
context.SaveChanges();
}
}
}
NPOIServices.cs
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XWPF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
namespace NPOItest.Models.Sevices
{
public class NPOIServices
{
private NPOIModel db = new NPOIModel();
public HSSFWorkbook AccountEmpty_E(FileStream fs)
{
HSSFWorkbook templateWorkbook = new HSSFWorkbook(fs);
HSSFSheet ws = (HSSFSheet)templateWorkbook.GetSheetAt(0);
ws.GetRow(1).GetCell(2).SetCellValue(DateTime.Now.ToString("yyyy/MM/dd"));
return templateWorkbook;
}
public HSSFWorkbook AccountData_E(FileStream fs)
{
List<Account> data = db.Account.ToList();
HSSFWorkbook templateWorkbook = new HSSFWorkbook(fs);
HSSFSheet ws = (HSSFSheet)templateWorkbook.GetSheetAt(0);
ws.GetRow(1).GetCell(2).SetCellValue(DateTime.Now.ToString("yyyy/MM/dd"));
int startRow = 3;
int i = 1;
foreach (Account item in data)
{
ws.GetRow(startRow).GetCell(0).SetCellValue(i.ToString());
ws.GetRow(startRow).GetCell(1).SetCellValue(item.Username);
ws.GetRow(startRow).GetCell(2).SetCellValue(item.Name);
ws.GetRow(startRow).GetCell(3).SetCellValue(item.Email);
ws.GetRow(startRow).GetCell(4).SetCellValue(item.Sex);
ws.GetRow(startRow).GetCell(5).SetCellValue(item.Company);
ws.GetRow(startRow).GetCell(6).SetCellValue(item.Position);
ws.GetRow(startRow).GetCell(7).SetCellValue(item.Phone);
startRow++;
i++;
}
ws.ShiftRows(ws.LastRowNum + 1, ws.LastRowNum + (ws.LastRowNum - startRow + 1), -(ws.LastRowNum - startRow + 1));
return templateWorkbook;
}
public string InsertData_E(HSSFWorkbook excel)
{
HSSFSheet ws = (HSSFSheet)excel.GetSheetAt(0);
List<Account> newAccounts = new List<Account>();
int startRow = 3;
for (int i = startRow; i <= ws.LastRowNum; i++)
{
newAccounts.Add(new Account
{
Username = ws.GetRow(startRow).GetCell(1).StringCellValue,
Password = "520520",
Name = ws.GetRow(startRow).GetCell(2).StringCellValue,
Email = ws.GetRow(startRow).GetCell(3).StringCellValue,
Sex = ws.GetRow(startRow).GetCell(4).StringCellValue,
Company = ws.GetRow(startRow).GetCell(5).StringCellValue,
Position = ws.GetRow(startRow).GetCell(6).StringCellValue,
Phone = ws.GetRow(startRow).GetCell(7).StringCellValue
});
startRow++;
}
db.Account.AddRange(newAccounts);
db.SaveChanges();
return "Success !";
}
public XWPFDocument AccountEmpty_W(FileStream fs)
{
XWPFDocument templateWorkbook = new XWPFDocument(fs);
XWPFTable tb = templateWorkbook.Tables[0];
tb.GetRow(0).GetCell(1).SetText(DateTime.Now.ToString("yyyy/MM/dd"));
return templateWorkbook;
}
public XWPFDocument AccountData_W(FileStream fs)
{
List<Account> data = db.Account.ToList();
XWPFDocument templateWorkbook = new XWPFDocument(fs);
XWPFTable tb = templateWorkbook.Tables[0];
tb.GetRow(0).GetCell(1).SetText(DateTime.Now.ToString("yyyy/MM/dd"));
int startRow = 3;
int i = 1;
foreach (Account item in data)
{
tb.CreateRow().CreateCell();
tb.GetRow(startRow).GetCell(0).SetText(i.ToString());
tb.GetRow(startRow).GetCell(1).SetText(item.Username);
tb.GetRow(startRow).GetCell(2).SetText(item.Name);
tb.GetRow(startRow).CreateCell();
tb.GetRow(startRow).GetCell(3).SetText(item.Email);
tb.GetRow(startRow).CreateCell();
tb.GetRow(startRow).GetCell(4).SetText(item.Sex);
tb.GetRow(startRow).CreateCell();
tb.GetRow(startRow).GetCell(5).SetText(item.Company);
tb.GetRow(startRow).CreateCell();
tb.GetRow(startRow).GetCell(6).SetText(item.Position);
tb.GetRow(startRow).CreateCell();
tb.GetRow(startRow).GetCell(7).SetText(item.Phone);
startRow++;
i++;
}
return templateWorkbook;
}
public string InsertData_W(XWPFDocument word)
{
XWPFTable tb = word.Tables[0];
List<Account> newAccounts = new List<Account>();
int startRow = 3;
for (int i = startRow; i <= 5; i++)
{
newAccounts.Add(new Account
{
Username = tb.GetRow(startRow).GetCell(1).GetText(),
Password = "520520",
Name = tb.GetRow(startRow).GetCell(2).GetText(),
Email = tb.GetRow(startRow).GetCell(3).GetText(),
Sex = tb.GetRow(startRow).GetCell(4).GetText(),
Company = tb.GetRow(startRow).GetCell(5).GetText(),
Position = tb.GetRow(startRow).GetCell(6).GetText(),
Phone = tb.GetRow(startRow).GetCell(7).GetText()
});
startRow++;
}
db.Account.AddRange(newAccounts);
db.SaveChanges();
return "Success !";
}
}
}
ConvertPDFHelper.cs
using System;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Excel;
namespace NPOItest.Models.Sevices
{
public class ConvertPDFHelper
{
public string ConvertExcelToPdf(string inputFile, string pdfPath)
{
Application excelApp = new Application();
excelApp.Visible = false;
Workbook workbook = null;
Workbooks workbooks = null;
try
{
workbooks = excelApp.Workbooks;
workbook = workbooks.Open(inputFile);
workbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,
pdfPath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
}
finally
{
if (workbook != null)
{
workbook.Close(XlSaveAction.xlDoNotSaveChanges);
while (Marshal.FinalReleaseComObject(workbook) != 0) { };
workbook = null;
}
if (workbooks != null)
{
workbooks.Close();
while (Marshal.FinalReleaseComObject(workbooks) != 0) { };
workbooks = null;
}
if (excelApp != null)
{
excelApp.Quit();
excelApp.Application.Quit();
while (Marshal.FinalReleaseComObject(excelApp) != 0) { };
excelApp = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
}
return pdfPath;
}
}
}
Controllers資料夾
NPOIController.cs
using NPOI.HSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NPOItest.Models.Sevices;
using NPOI.XWPF.UserModel;
namespace NPOItest.Controllers
{
public class NPOIController : Controller
{
private string fileSavedPath = "~/Content/";
private NPOIServices NPServices = new NPOIServices();
// GET: NPOI Excel
public void EmptyExport_E()
{
FileStream fs = new FileStream(string.Concat(Server.MapPath(fileSavedPath), "/Excels/temp.xls"), FileMode.Open, FileAccess.ReadWrite);
HSSFWorkbook templateWorkbook = NPServices.AccountEmpty_E(fs);
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlPathEncode("AccountEmpty.xls"));
MemoryStream ms = new MemoryStream();
templateWorkbook.Write(ms);
ms.WriteTo(Response.OutputStream);
Response.End();
}
// GET: NPOI Excel
public void DataExport_E()
{
FileStream fs = new FileStream(string.Concat(Server.MapPath(fileSavedPath), "/Excels/temp.xls"), FileMode.Open, FileAccess.ReadWrite);
HSSFWorkbook templateWorkbook = NPServices.AccountData_E(fs);
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlPathEncode("AccountData.xls"));
MemoryStream ms = new MemoryStream();
templateWorkbook.Write(ms);
ms.WriteTo(Response.OutputStream);
Response.End();
}
// GET: NPOI EXCEL to PDF
public void PDFExport_E()
{
FileStream fs = new FileStream(string.Concat(Server.MapPath(fileSavedPath), "/Excels/temp.xls"), FileMode.Open, FileAccess.ReadWrite);
HSSFWorkbook templateWorkbook = NPServices.AccountData_E(fs);
MemoryStream ms = new MemoryStream();
templateWorkbook.Write(ms);
string target = string.Concat(Server.MapPath(fileSavedPath), "/temp/" + System.Guid.NewGuid().ToString() + "EXCEL.xls");//??
using (var fileStream = new FileStream(target, FileMode.CreateNew, FileAccess.ReadWrite))
{
ms.Position = 0;
ms.CopyTo(fileStream); // fileStream is not populated
}
ConvertPDFHelper Convert = new ConvertPDFHelper();
string pdfPath = string.Concat(Server.MapPath(fileSavedPath), "/Excels/temp/" + System.Guid.NewGuid().ToString() + ".pdf");
string PDFfile = Convert.ConvertExcelToPdf(target, pdfPath);
Stream iStream = new FileStream(PDFfile, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
MemoryStream memoryStream = new MemoryStream();
iStream.CopyTo(memoryStream);
iStream.Dispose();
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlPathEncode("AccountPDF.pdf"));
memoryStream.WriteTo(Response.OutputStream);
Response.End();
}
// POST: NPOI Excel
[HttpPost]
public ActionResult Import_E(HttpPostedFileBase file)
{
string message;
if (file != null && file.ContentLength > 0 && file.ContentLength < (10 * 1024 * 1024))
{
string filetype = file.FileName.Split('.').Last();
string fileName = Path.GetFileName(file.FileName);
string path = Path.Combine(Server.MapPath("~/Content/Imports"), fileName);
if (filetype == "xls")
{
file.SaveAs(path);
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
HSSFWorkbook excel = new HSSFWorkbook(fs);
message = NPServices.InsertData_E(excel);
}
else
{
message = "File format error !";
}
}
else
{
message = "Please select file import !";
}
ViewBag.Message = message;
return View();
}
// GET: NPOI Word
public void EmptyExport_W()
{
FileStream fs = new FileStream(string.Concat(Server.MapPath(fileSavedPath), "/Excels/temp.docx"), FileMode.Open, FileAccess.ReadWrite);
XWPFDocument templateWorkbook = NPServices.AccountEmpty_W(fs);
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlPathEncode("AccountEmpty.docx"));
MemoryStream ms = new MemoryStream();
templateWorkbook.Write(ms);
ms.WriteTo(Response.OutputStream);
Response.End();
}
// GET: NPOI Word
public void DataExport_W()
{
FileStream fs = new FileStream(string.Concat(Server.MapPath(fileSavedPath), "/Excels/temp.docx"), FileMode.Open, FileAccess.ReadWrite);
XWPFDocument templateWorkbook = NPServices.AccountData_W(fs);
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlPathEncode("AccountData.docx"));
MemoryStream ms = new MemoryStream();
templateWorkbook.Write(ms);
ms.WriteTo(Response.OutputStream);
Response.End();
}
// GET: NPOI Word TO PDF
public void PDFExport_W()
{
FileStream fs = new FileStream(string.Concat(Server.MapPath(fileSavedPath), "/Excels/temp.docx"), FileMode.Open, FileAccess.ReadWrite);
XWPFDocument templateWorkbook = NPServices.AccountData_W(fs);
MemoryStream ms = new MemoryStream();
templateWorkbook.Write(ms);
string target = string.Concat(Server.MapPath(fileSavedPath), "/temp/" + System.Guid.NewGuid().ToString() + "Word.docx");//??
using (var fileStream = new FileStream(target, FileMode.CreateNew, FileAccess.ReadWrite))
{
ms.Position = 0;
ms.CopyTo(fileStream); // fileStream is not populated
}
ConvertPDFHelper Convert = new ConvertPDFHelper();
string pdfPath = string.Concat(Server.MapPath(fileSavedPath), "/Excels/temp/" + System.Guid.NewGuid().ToString() + ".pdf");
string PDFfile = Convert.ConvertExcelToPdf(target, pdfPath);
Stream iStream = new FileStream(PDFfile, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
MemoryStream memoryStream = new MemoryStream();
iStream.CopyTo(memoryStream);
iStream.Dispose();
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlPathEncode("AccountPDF.pdf"));
memoryStream.WriteTo(Response.OutputStream);
Response.End();
}
// POST: NPOI Word
[HttpPost]
public ActionResult Import_W(HttpPostedFileBase file)
{
string message;
if (file != null && file.ContentLength > 0 && file.ContentLength < (10 * 1024 * 1024))
{
string filetype = file.FileName.Split('.').Last();
string fileName = Path.GetFileName(file.FileName);
string path = Path.Combine(Server.MapPath("~/Content/Imports"), fileName);
if (filetype == "docx")
{
file.SaveAs(path);
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
XWPFDocument word = new XWPFDocument(fs);
message = NPServices.InsertData_W(word);
}
else
{
message = "File format error !";
}
}
else
{
message = "Please select file import !";
}
ViewBag.Message = message;
return View();
}
}
}
Views資料夾
Index.cshtml
@{
ViewBag.Title = "Home Page";
}
<div class="jumbotron">
<h1>NPOI Excel</h1>
<p>
<button class="btn btn-primary btn-lg" onclick="location.href='@Url.Action("EmptyExport_E", "NPOI")'">
帳戶空資料庫匯出»
</button>
</p>
<br />
<p>
<button class="btn btn-primary btn-lg" onclick="location.href='@Url.Action("DataExport_E", "NPOI")'">
帳戶資料匯出 »
</button>
</p>
<br />
<button class="btn btn-primary btn-lg" onclick="location.href='@Url.Action("PDFExport_E", "NPOI")'">
PDF匯出 »
</button>
<br />
<br />
<form class="form-horizontal form-group" id="UploadForm" action="@Url.Action("Import_E", "NPOI")" method="post" enctype="multipart/form-data">
<label for="file" style="font-size:17px">匯入Excel :</label>
<input class="form-control btn btn-default btn-lg" type="file" name="file" id="file" />
<input type="submit" value="Import Excel" class="btn btn-primary btn-lg" />
</form>
</div>
<div class="jumbotron">
<h1>NPOI Word</h1>
<p>
<button class="btn btn-primary btn-lg" onclick="location.href='@Url.Action("EmptyExport_W", "NPOI")'">
帳戶空資料庫匯出 »
</button>
</p>
<br />
<p>
<button class="btn btn-primary btn-lg" onclick="location.href='@Url.Action("DataExport_W", "NPOI")'">
帳戶資料庫匯出 »
</button>
</p>
<br />
<button class="btn btn-primary btn-lg" onclick="location.href='@Url.Action("PDFExport_W", "NPOI")'">
PDF匯出 »
</button>
<br />
<br />
<form class="form-horizontal form-group" id="UploadForm" action="@Url.Action("Import_W", "NPOI")" method="post" enctype="multipart/form-data">
<label for="file" style="font-size:17px">匯入Word :</label>
<input class="form-control btn btn-default btn-lg" type="file" name="file" id="file" />
<input type="submit" value="Import Word" class="btn btn-primary btn-lg" />
</form>
</div>
Import_E.cshtml
@{
ViewBag.Title = "Result";
}
<h2>Result</h2>
<h3>@ViewBag.Message</h3>
Import_W.cshtml
@{
ViewBag.Title = "Result";
}
<h2>Result</h2>
<h3>@ViewBag.Message</h3>
執行結果如圖:
相關推薦
NPOI匯出和匯入Excel,Word和PDF
Models資料夾 NPOIModel.cs namespace NPOItest.Models { using System; using System.Data.Entity; using System.ComponentMo
java後端匯入excel模板和匯入excel檔案去讀資料
模板轉載地址:https://www.cnblogs.com/zhangyangtao/p/9802948.html 直接上程式碼(我是基於ssm寫的demo,匯入檔案目前只能讀取.xls字尾的excel檔案) 1 <!--匯入的核心依賴--> 2 <depende
Java的poi技術讀取和匯入Excel簡單例項
專案結構: 用到的Excel檔案: XlsMain .java 類 //該類有main方法,主要負責執行程式,同時該類中也包含了用poi讀取Excel(2003版) import java.io.FileInputStream; import java.io.
ef+Npoi匯出百萬行excel之踩坑記
最近在做一個需求是匯出較大的excel,本文是記錄我在做需求過程中遇到的幾個問題和解題方法,給大家分享一下,一來可以幫助同樣遇到問題的朋友,二呢,各位大神也許有更好的方法可以指點小弟一下,讓我順便學習一下。 背景::工頭:“小鐘啊,xx介面加個匯出exc
關於NPOI匯出excel檔案(xls和xlsx兩種格式)提示格式不符的問題
這兩天在做匯出excel檔案的時候遇到這個問題 本來我匯出的格式是xlsx格式的,但是下載得到的檔案格式變成了xls, 一開始以為是返回的contenttype設定錯了 return File(ms, "application/vnd.ms-excel", "新車型匯入模板檔案.xls
匯出pdf檔案、匯出excel檔案和列印
此處所介紹的是利用一些jQuery外掛實現匯出pdf檔案、匯出excel檔案和列印的方法。 1.匯出pdf檔案 (1)需要匯入兩個檔案:jspdf.debug.js,html2canvas.js &nb
使用PL/SQL Developer工具匯入excel和匯出excel
匯出: 1.執行 select 語句查詢出需要匯出的資料. 2.在資料列表中右鍵,選擇save results.儲存為.csv檔案,然後已excel方式開啟就OK了.可以另存為xsl。需要注意的是如果列內容是純數字 的話,匯出時會自動把前面的0去掉,想要匯出完整的列內容,最
JAVA-Aspose將WORD和Excel轉成PDF
JAVA將Word轉成PDF 有通過dll擴充套件庫,Jacob的方式,這種方式必須本地安裝了Word,不能跨平臺 通過Aspose的方式,該功能是付費版,需要破解,我本地測試Excel有水印,無法
[PHP] PHP操作Excel匯出和匯入,使用PHPExcel第三方類操作
下載的官方文件,如上圖。對於專案真正有用的事Classes資料夾,將Classes更名為PHPExcel放到自己專案類庫中,以下是Thinkphp框架下的類庫存放目錄。 2. 下面匯出的使用與實踐 //將資料匯出到Excel表
POI和Java Excel Api匯入匯出----詳細到你不敢相信
來自:http://blog.csdn.net/jerehedu/article/details/45195359 一、介紹 當前B/S模式已成為應用開發的主流,而在企業辦公系統中,常常有客戶這樣子要求:你要把我們的報表直接用
excel匯入到html和從html匯出檔案到excel
公司最近需求。所以做了一個。下面是一些可執行的程式碼html:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-t
thinkphp5封裝匯入excel和匯出excel
開發中有時候要做excel的匯入匯出功能,而thinkphp5有其封裝的匯入方法,十分方便,下面說下怎麼使用。 首先,要下載一下phpExcel,這個大家就自己到百度上面下載,一搜索就會有的了,下載後解壓出來是這樣的 然後將資料夾複製到專案中的vendo
excel匯入到Mysql 和 mysql資料匯出到excel
經過了那麼長時間的實踐,貌似找到了最簡單的一種方法: 1.mysql匯出到excel: 1.1.SELECT * INTO OUTFILE '/test.xls' FROM table1; 2.excel匯入到mysql: 2.1.將選中的資料塊兒拷貝到一個TXT文字
Java Excel匯入匯出,基於XML和Easy-excel使用
1.前言 •在工作時,遇到過這樣的需求,需要靈活的對工單進行匯入或匯出,以前自己也做過,但使用不靈活繁瑣。我想能不能像配置檔案一樣可配置的匯入匯出,那樣使用起來就方便許多。 2.SpringMVC專案搭建 •建立基於Maven版本管理Springmvc專案
java匯出word、pdf之新增頁首----頁首(指定格式,包括圖片和文字)
doc.open(); // 新增頁首 Image headerImage = Image.getInstance("f:\\1.jpg"); headerImage.scaleAbsolute(36, 36); Paragraph headerPara
Magicodes.IE已支援匯出Word、Pdf和Html
關於Magicodes.IE 匯入匯出通用庫,通過匯入匯出DTO模型來控制匯入和匯出,支援Excel、Word、Pdf和Html。 GitHub地址:https://github.com/xin-lai/Magicodes.IE 特點 需配合相關匯入匯出的DTO模型使用,支援通過D
通過swagger json一鍵解析為html頁面、匯出word和excel的解析演算法分享
寫在前面: 完全通過Spring Boot工程 Java程式碼,將swagger json 一鍵解析為html頁面、匯出word和execel的解析演算法,不需要任何網上那些類似於“SwaggerMarkup2”等外掛來實現。 由於業務需要,準備開發一個openapi開放平臺,類似於阿
Java實現PDF和Excel生成和資料動態插入以及匯出
一、序言 Excel、PDF的匯出、匯入是我們工作中經常遇到的一個問題,剛好今天公司業務遇到了這個問題,順便記個筆記以防下次遇到相同的問題而束手無策。 公司有這麼兩個需求: 需求一、給了一個表單,讓把查出來的資料組裝到表單中並且提供以PDF格式的下載功能。 需求二、將資料查出來以Excel表格的形式下載下來。
Word VBA(批量復制Excel表格和Word表格到Word中)
lap bre quotient display wds bubuko work http OS unction Test() ‘使用雙字典 SearchPath = FolderDialog("請選擇文件夾") If SearchPath =
使用empdp和impdp匯出和匯入資料庫的表
資料泵技術比原來匯入/匯出(imp,exp)技術快15-45倍。速度的提高源於使用了並行技術來讀寫匯出轉儲檔案。此命令只可用在服務端,客戶端無法使用。 1.開啟SQL plus 首先需要輸入使用者名稱和密碼進行登入; 建立一個directory物件:create directory dp