Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 美国黄色片免费看,国产精品久久久亚洲,日本一区二区三区视频在线

          整合營(yíng)銷服務(wù)商

          電腦端+手機(jī)端+微信端=數(shù)據(jù)同步管理

          免費(fèi)咨詢熱線:

          ASP.NET 導(dǎo)出Excel和導(dǎo)入Excel并插入

          ASP.NET 導(dǎo)出Excel和導(dǎo)入Excel并插入數(shù)據(jù)庫(kù)

          臺(tái)拖一個(gè)Gridview,在拖一個(gè)導(dǎo)出excel的按鈕,給這個(gè)按鈕添加事件
          后臺(tái)代碼:

          using BLL;
          using Model;
          
          namespace Web
          {
              public partial class ExcelOperate : System.Web.UI.Page
              {
                  private StudentBLL bll=new StudentBLL();
                  protected void Page_Load(object sender, EventArgs e)
                  {
                      if (!IsPostBack)
                      {
                          Bind();
                      }
                  }
          
                  //綁定數(shù)據(jù)
                  private void Bind()
                  {
                      GridView1.DataSource=bll.GetAllStu(null);
                      GridView1.DataBind();
                  }
                  #region 導(dǎo)出到excel
          
                  //導(dǎo)出excel
                  protected void btnExcelout_Click(object sender, EventArgs e)
                  {
                      string style=@"<style> .text { mso-number-format:\@; } </script> "; //設(shè)置格式
                      Response.ClearContent();
                      Response.ContentEncoding=Encoding.GetEncoding("gbk");
                      Response.AddHeader("content-disposition", "attachment;filename=ouput.xls");
                      Response.ContentType="application/excel";
                      StringWriter sw=new StringWriter();
                      HtmlTextWriter htw=new HtmlTextWriter(sw);
                      GridView1.RenderControl(htw);
                      Response.Write(style);//注意
                      Response.Write(sw.ToString());
                      Response.End();
                  }
                  //注意:必須覆蓋此方法
                  public override void VerifyRenderingInServerForm(Control control)
                  {
                      //base.VerifyRenderingInServerForm(control);
                  }
                  //解決數(shù)字字符串顯示不完全
                  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
                  {
                      // e.Row.Cells[3].Attributes.Add("class", "text");//在數(shù)據(jù)綁定中設(shè)置格式
                      //哪一列需要顯示文本的,加上下面這句話即可
                      e.Row.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
                  } 
                  #endregion
              }
          }

          頁(yè)面效果:


          導(dǎo)入Excel并保存到數(shù)據(jù)庫(kù):
          前臺(tái)需要拖一個(gè)FileUpload上傳控件,一個(gè)導(dǎo)入excel按鈕,給其添加事件:

          //導(dǎo)入excel數(shù)據(jù)
                  protected void btnExcelIn_Click(object sender, EventArgs e)
                  {
                      string filepath=string.Empty;
                      string getErrormg=string.Empty;
                      DataTable dt=new DataTable();
                      if (!fuFile.HasFile)
                      {
                          Response.Write("<script>alert('請(qǐng)選擇你要導(dǎo)入的Excel文件');</script>");
                          return;
                      }
                      //獲取文件的后綴名
                      string fileExt=System.IO.Path.GetExtension(fuFile.FileName);
                      if (fileExt !=".xls")
                      {
                          Response.Write("<script>alert('文件類型錯(cuò)誤!');</script>");
                          return;
                      }
                      //獲取絕對(duì)路徑
                      filepath=fuFile.PostedFile.FileName;
                      string conn="Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";Data Source=" + filepath;
                      OleDbConnection excelCon=new OleDbConnection(conn);
                      //Excel文件里面工作表名 默認(rèn)為Sheet1,后面需要加上$符號(hào)[工作表名稱$]切記,不然會(huì)報(bào)錯(cuò)
                      OleDbDataAdapter odda=new OleDbDataAdapter("SELECT * FROM [Sheet1$]", excelCon);
                      try
                      {
                          odda.Fill(dt);
                      }
                      catch (Exception ex)
                      {
                          Response.Write(ex.Message);
                          Response.Write("<script>alert('" + ex.Message + "!')</script>");
                      }
                      finally
                      {
                          excelCon.Close();
                          excelCon.Dispose();
                      }
                      //將數(shù)據(jù)寫到數(shù)據(jù)庫(kù)里面
                      try
                      {
                        
                          for (int i=0; i < dt.Rows.Count; i++)
                          {
                              Studnet stu=new Studnet();
                              stu.C_id=Convert.ToInt32(dt.Rows[i]["c_id"]);
                              stu.No=dt.Rows[i]["no"].ToString();
                              stu.Name=dt.Rows[i]["name"].ToString();
                              stu.Gender=dt.Rows[i]["gender"].ToString()=="男" ? true : false;
                              stu.Age=Convert.ToInt32(dt.Rows[i]["age"].ToString());
                              bll.InsertStu(stu);
                          }
          
                      }
                      catch (Exception ex)
                      {
          
                          getErrormg=ex.Message;
                          Response.Write(ex.Message);
                      }
          
                      if (getErrormg=="")
                      {
                          Response.Write("<script>alert('導(dǎo)入Excel文件成功!')</script>");
                          Bind();
                      }
                      else { Response.Write("<script>alert('導(dǎo)入Excel文件失敗!')</script>"); }
          
                  }

          Excel和導(dǎo)入后的頁(yè)面效果:




          數(shù)據(jù)庫(kù)在導(dǎo)入excel數(shù)據(jù)之前和時(shí)候的效果:



          這里要注意幾個(gè)地方,一般導(dǎo)出excel的時(shí)候,數(shù)字文本會(huì)把前面的0都省略掉了,這里需要注意:紅色代碼片段,導(dǎo)入的時(shí)候,也有個(gè)***紅紅紅色***標(biāo)記碼塊要注意
          以下是前臺(tái)完整代碼:

          <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ExcelOperate.aspx.cs" Inherits="Web.ExcelOperate" %>
          
          <!DOCTYPE html>
          
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head runat="server">
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
              <title></title>
          </head>
          <body>
              <form id="form1" runat="server">
              <div>
                  <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"></asp:GridView>
                  <br />
                  <asp:Button ID="btnExcelout" runat="server" OnClick="btnExcelout_Click" Text="導(dǎo)出到Excel" />
                  <br />
                  <asp:FileUpload ID="fuFile" runat="server" />
                  <asp:Button ID="btnExcelIn" runat="server" OnClick="btnExcelIn_Click" Text="導(dǎo)入Excel數(shù)據(jù)" />
              </div>
              </form>
          </body>
          </html>

          以下是后臺(tái)完整代碼:

          web應(yīng)用程序開發(fā)時(shí),或許你會(huì)遇到這樣的需求,如何在 Asp.Net Core 中實(shí)現(xiàn) excel 或者 word 的導(dǎo)入導(dǎo)出,在 NuGet 上有大量的工具包可以實(shí)現(xiàn)這樣的功能,本篇就討論下如何使用 ClosedXML 實(shí)現(xiàn) Excel 數(shù)據(jù)導(dǎo)出。

          安裝 ClosedXML

          如果想實(shí)現(xiàn) Excel 的導(dǎo)出功能,在 Asp.Net Core 中有很多的dll可以做到,其中的一個(gè)叫做 ClosedXML,你可以通過(guò)可視化界面 NuGet package manager 去安裝,也可以使用命令行 NuGet package manager console 執(zhí)行下面命令。

          
          Install-Package ClosedXML
          

          將數(shù)據(jù)導(dǎo)出成 CSV 文件

          將數(shù)據(jù)導(dǎo)成 CSV 文件是非常簡(jiǎn)單的,畢竟每行數(shù)據(jù)都是用 , 隔開即可,可以用 NuGet 上的 CsvExport 或者 AWright18.SimpleCSVExporter 去實(shí)現(xiàn),當(dāng)然你覺得自己很 ,可以親自操刀實(shí)現(xiàn),下面我準(zhǔn)備親自實(shí)現(xiàn)一下,先看下面定義的 Author 類。

          
          public class Author
          {
            public int Id { get; set; }
            public string FirstName { get; set; }
            public string LastName { get; set; }
          }
          

          然后塞一些數(shù)據(jù)到 authors 列表中,如下代碼所示:

          
          List<Author> authors=new List<Author>
          {
              new Author { Id=1, FirstName="Joydip", LastName="Kanjilal" },
              new Author { Id=2, FirstName="Steve", LastName="Smith" },
              new Author { Id=3, FirstName="Anand", LastName="Narayaswamy"}
          };
          

          定義一個(gè) DownloadCommaSeperatedFile 方法,用于實(shí)現(xiàn) Action 的 csv 導(dǎo)出功能。

          
          public IActionResult DownloadCommaSeperatedFile()
          {
              try
              {
                 StringBuilder stringBuilder=new StringBuilder();
                 stringBuilder.AppendLine("Id,FirstName,LastName");
                 foreach (var author in authors)
                 {
                     stringBuilder.AppendLine($"{author.Id},
                     {author.FirstName},{author.LastName}");
                 }
                return File(Encoding.UTF8.GetBytes
                (stringBuilder.ToString()), "text/csv", "authors.csv");
              }
              catch
              {
                 return Error();
              }
          }
          

          將數(shù)據(jù)導(dǎo)出成 XLSX 文件

          Excel 中的 workbook 是由若干個(gè) worksheet 組成,下面的代碼可用來(lái)生成一個(gè) workbook。

          
          var workbook=new XLWorkbook();
          

          接下來(lái)生成一個(gè) worksheet,然后在 worksheet 中填一些數(shù)據(jù),代碼如下:

          
          IXLWorksheet worksheet=workbook.Worksheets.Add("Authors");
          worksheet.Cell(1, 1).Value="Id";
          worksheet.Cell(1, 2).Value="FirstName";
          worksheet.Cell(1, 3).Value="LastName";
          for (int index=1; index <=authors.Count; index++)
          {
             worksheet.Cell(index + 1, 1).Value=authors[index - 1].Id;
             worksheet.Cell(index + 1, 2).Value=authors[index - 1].FirstName;
             worksheet.Cell(index + 1, 3).Value=authors[index - 1].LastName;
          }
          

          最后,將 workbook 轉(zhuǎn)成 內(nèi)存流 (memory stream) 再通過(guò) Controller.Action 的 FileContentResult 返回給客戶端,代碼如下:

          
          using (var stream=new MemoryStream())
          {
               workbook.SaveAs(stream);
               var content=stream.ToArray();
               return File(content, contentType, fileName);
          }
          

          下載 Excel

          下面是導(dǎo)出 Excel 所有的業(yè)務(wù)邏輯代碼,這個(gè) Action 實(shí)現(xiàn)了 Excel 導(dǎo)出功能。

          
                  public IActionResult DownloadExcelDocument()
                  {
                      string contentType="application/vnd.openxmlformats-
                      officedocument.spreadsheetml.sheet";
                      string fileName="authors.xlsx";
                      try
                      {
                          using (var workbook=new XLWorkbook())
                          {
                              IXLWorksheet worksheet=            workbook.Worksheets.Add("Authors");
                              worksheet.Cell(1, 1).Value="Id";
                              worksheet.Cell(1, 2).Value="FirstName";
                              worksheet.Cell(1, 3).Value="LastName";
                              for (int index=1; index <=authors.Count; index++)
                              {
                                  worksheet.Cell(index + 1, 1).Value=                authors[index - 1].Id;
                                  worksheet.Cell(index + 1, 2).Value=                authors[index - 1].FirstName;
                                  worksheet.Cell(index + 1, 3).Value=                authors[index - 1].LastName;
                              }
                              using (var stream=new MemoryStream())
                              {
                                  workbook.SaveAs(stream);
                                  var content=stream.ToArray();
                                  return File(content, contentType, fileName);
                              }
                          }
                      }
                      catch(Exception ex)
                      {
                          return Error();
                      }
                  }
          

          這篇就是 ClosedXML 的所有內(nèi)容,如果你想對(duì) Excel 中的數(shù)據(jù)進(jìn)行更加復(fù)雜的操控,可以使用 EPPlus 或者 NPOI,關(guān)于 ClosedXML 的更多內(nèi)容,可參考:https://github.com/ClosedXML/ClosedXML

          譯文鏈接:https://www.infoworld.com/article/3538413/how-to-export-data-to-excel-in-aspnet-core-30.html

          更多高質(zhì)量干貨:參見我的 GitHub: dotnetfly**

          能轉(zhuǎn)換:R圖和統(tǒng)計(jì)表轉(zhuǎn)成發(fā)表級(jí)的Word、PPT、Excel、HTML、Latex、矢量圖等

          R包export可以輕松的將R繪制的圖和統(tǒng)計(jì)表輸出到 Microsoft Office (Word、PowerPoint和Excel)、HTML和Latex中,其質(zhì)量可以直接用于發(fā)表。

          • 你和PPT高手之間,就只差一個(gè)iSlide
          • Excel改變了你的基因名,30% 相關(guān)Nature文章受影響,NCBI也受波及


          特點(diǎn)

          1. 可以用命令將交互式R圖或ggplot2Latticebase R圖保存到Microsoft Word、Powerpoint或其他各種位圖或矢量格式。
          2. 完全可編輯的Powerpoint矢量格式輸出,支持手動(dòng)整理繪圖布局。
          3. 統(tǒng)計(jì)分析的輸出保存為Excel、Word、PowerPoint、Latex或HTML文檔的表格形式。
          4. 自定義R輸出格式。

          安裝

          export包可以在Windows、Ubuntu和Mac上跨平臺(tái)運(yùn)行。不過(guò)有些Mac發(fā)行版默認(rèn)情況下沒(méi)有安裝cairo設(shè)備,需要自行安裝。如果Mac用戶已安裝XQuartz,這個(gè)問(wèn)題就解決了,它可以從https://www.xquartz.org/免費(fèi)獲得。

          官方CRAN發(fā)布 (以不能用)

          install.packages("export")

          從 Github 安裝 (推薦


          install.packages("officer")
          install.packages("rvg")
          install.packages("openxlsx")
          install.packages("ggplot2")
          install.packages("flextable")
          install.packages("xtable")
          install.packages("rgl")
          install.packages("stargazer")
          install.packages("tikzDevice")
          install.packages("xml2")
          install.packages("broom")
          install.packages("devtools")
          devtools::install_github("tomwenseleers/export")
          


          該包主要包括以下幾種轉(zhuǎn)換

          • graph2bitmap
          • graph2office
          • graph2vector
          • rgl2bitmap 轉(zhuǎn)換3D圖
          • table2office
          • table2spreadsheet
          • table2tex
          • graph2bitmap: 將當(dāng)前R圖保存到bmp文件中
          • graph2png: 將當(dāng)前R圖保存到png文件中
          • graph2tif: 將當(dāng)前R圖保存到TIF文件中
          • graph2jpg: 將當(dāng)前R圖保存為JPEG文件

          使用幫助信息如下

          graph2bitmap(x=NULL, file="Rplot", fun=NULL, type=c("PNG","JPG", "TIF"),
                  aspectr=NULL, width=NULL, height=NULL, dpi=300,scaling=100,
                  font=ifelse(Sys.info()["sysname"]=="Windows", "Arial",
                  "Helvetica")[[1]], bg="white", cairo=TRUE,
                  tiffcompression=c("lzw", "rle", "jpeg", "zip", "lzw+p", "zip+p"),
                  jpegquality=99, ...)
          
          • aspectr: 期望縱橫比。如果設(shè)置為空,則使用圖形設(shè)備的縱橫比。
          • width: 所需寬度(英寸);可以與期望的縱橫比aspectr組合。
          • height: 所需高度(英寸);可以與期望的縱橫比aspectr組合。
          • scaling: 按一定比例縮放寬度和高度。
          • font: PNG和TIFF輸出中標(biāo)簽所需的字體; Windows系統(tǒng)默認(rèn)為Arial,其他系統(tǒng)默認(rèn)為Helvetica。
          • bg: 所需的背景顏色,例如“白色”或“透明”。
          • cairo: 邏輯,指定是否使用Cairographics導(dǎo)出。
          • tiffcompression: 用于TIF文件的壓縮。
          • jpegquality: JPEG壓縮的質(zhì)量。

          準(zhǔn)備開始

          安裝完 export包后,先調(diào)用該包

          library(export)
          

          用ggplot2繪圖

          library(ggplot2)
          library(datasets)
          
          x=qplot(Sepal.Length, Petal.Length, data=iris,
                  color=Species, size=Petal.Width, alpha=I(0.7))
          

          qplot()的意思是快速作圖,利用它可以很方便的創(chuàng)建各種復(fù)雜的圖形,其他系統(tǒng)需要好幾行代碼才能解決的問(wèn)題,用qplot只需要一行就能完成。

          使用半透明的顏色可以有效減少圖形元素重疊的現(xiàn)象,要?jiǎng)?chuàng)建半透明的顏色,可以使用alpha圖形屬性,其值從0(完全透明)到1(完全不透明)。更多ggplot2繪圖見ggplot2高效實(shí)用指南 (可視化腳本、工具、套路、配色) (往期教程更有很多生物信息相關(guān)的例子)。

          鳶尾花(iris)是數(shù)據(jù)挖掘常用到的一個(gè)數(shù)據(jù)集,包含150個(gè)鳶尾花的信息,每50個(gè)取自三個(gè)鳶尾花種之一(setosa,versicolourvirginica)。每個(gè)花的特征用下面的5種屬性描述萼片長(zhǎng)度(Sepal.Length)、萼片寬度(Sepal.Width)、花瓣長(zhǎng)度(Petal.Length)、花瓣寬度(Petal.Width)、類(Species)。

          在console里展示數(shù)據(jù)圖 (長(zhǎng)寬比自己調(diào)節(jié)):

          導(dǎo)出圖形對(duì)象

          # 需運(yùn)行上面的ggplot2繪圖
          # Create a file name
          # 程序會(huì)自動(dòng)加后綴
          filen <- "output_filename" # or
          # filen <- paste("YOUR_DIR/ggplot")
          # There are 3 ways to use graph2bitmap():
          ### 1. Pass the plot as an object
          graph2png(x=x, file=filen, dpi=400, height=5, aspectr=4)
          graph2tif(x=x, file=filen, dpi=400, height=5, aspectr=4)
          graph2jpg(x=x, file=filen, dpi=400, height=5, aspectr=4)
          

          導(dǎo)出當(dāng)前繪圖窗口展示的圖

          ### 2. Get the plot from current screen device
          # 注意這個(gè)x,是運(yùn)行命令,展示圖像
          x
          graph2png(file=filen, dpi=400, height=5, aspectr=4)
          graph2tif(file=filen, dpi=400, height=5, aspectr=4)
          graph2jpg(file=filen, dpi=400, height=5, aspectr=4)
          

          導(dǎo)出自定義函數(shù)輸出的一組圖

          ### 3. Pass the plot as a functio
          plot.fun <- function(){
            print(qplot(Sepal.Length, Petal.Length, data=iris,
                        color=Species, size=Petal.Width, alpha=0.7))
          }
          graph2png(file=filen, fun=plot.fun, dpi=400, height=5, aspectr=4)
          graph2tif(file=filen, fun=plot.fun, dpi=400, height=5, aspectr=4)
          graph2jpg(file=filen, fun=plot.fun, dpi=400, height=5, aspectr=4)
          

          轉(zhuǎn)換后的圖形:

          與Office系列的交互

          大部分圖的細(xì)節(jié)修改都是用代碼完成的,不需要后續(xù)的修飾;但如果某一些修改比較特異,不具有程序的通用性特征,或?qū)崿F(xiàn)起來(lái)比較困難,就可以考慮后期修改。比如用AI文章用圖的修改和排版。熟悉PPT的,也可以用PPT,這時(shí)R的圖導(dǎo)出PPT,就要用到graph2office系列函數(shù)了。

          graph2ppt: 將當(dāng)前R圖保存到Microsoft Office PowerPoint/LibreOffice Impress演示文稿中。

          graph2doc:將當(dāng)前的R圖保存到Microsoft Office Word/LibreOffice Writer文檔中。

          函數(shù)參數(shù)展示和解釋

          graph2office(x=NULL, file="Rplot", fun=NULL, type=c("PPT", "DOC"),
                  append=FALSE, aspectr=NULL, width=NULL, height=NULL,scaling=100,
                  paper="auto", orient=ifelse(type[1]=="PPT","landscape", "auto"),
                  margins=c(top=0.5, right=0.5, bottom=0.5, left=0.5),
                  center=TRUE, offx=1, offy=1, upscale=FALSE, vector.graphic=TRUE, ...)
          
          • margins: 預(yù)設(shè)留白邊距向量。
          • paper: 紙張尺寸——“A5”至“A1”用于Powerpoint導(dǎo)出,或“A5”至“A3”用于Word輸出;默認(rèn)“auto”自動(dòng)選擇適合您的圖形的紙張大小。如果圖太大,無(wú)法在給定的紙張大小上顯示,則按比例縮小。
          • orient: 所需的紙張方向-“自動(dòng)”,“縱向”或“橫向”; Word輸出默認(rèn)為“自動(dòng)”,Powerpoint默認(rèn)為“橫向”。
          • vector.graphic: 指定是否以可編輯的向量DrawingML格式輸出。默認(rèn)值為TRUE,在這種情況下,編輯Powerpoint或Word中的圖形時(shí),可以先對(duì)圖形元素進(jìn)行分組。如果設(shè)置為FALSE,則將該圖以300 dpi的分辨率柵格化為PNG位圖格式。(柵(shān)格化,是PS中的一個(gè)專業(yè)術(shù)語(yǔ),柵格即像素,柵格化即將矢量圖形轉(zhuǎn)化為位圖。)

          同樣有3種導(dǎo)出方式

          # 需運(yùn)行上面的ggplot2繪圖
          # Create a file name
          filen <- "output_filename" # or
          # filen <- paste("YOUR_DIR/ggplot")
          # There are 3 ways to use graph2office():
          ### 1. Pass the plot as an object
          # 導(dǎo)出圖形對(duì)象
          graph2ppt(x=x, file=filen)
          graph2doc(x=x, file=filen, aspectr=0.5)
          ### 2. Get the plot from current screen device
          # 導(dǎo)出當(dāng)前預(yù)覽窗口呈現(xiàn)的圖
          x
          graph2ppt(file=filen, width=9, aspectr=2, append=TRUE)
          graph2doc(file=filen, aspectr=1.7, append=TRUE)
          ### 3. Pass the plot as a function
          # 導(dǎo)出自定義函數(shù)輸出的一系列圖
          graph2ppt(fun=plot.fun, file=filen, aspectr=0.5, append=TRUE)
          graph2doc(fun=plot.fun, file=filen, aspectr=0.5, append=TRUE)
          

          導(dǎo)出到office(ppt和word)中的圖形,是可編輯的:

          其它導(dǎo)出到ppt的例子(設(shè)置長(zhǎng)寬比)

          graph2ppt(file="ggplot2_plot.pptx", aspectr=1.7)
          

          增加第二張同樣的圖,9英寸寬和A4長(zhǎng)寬比的幻燈片 (append=T,追加)

          graph2ppt(file="ggplot2_plot.pptx", width=9, aspectr=sqrt(2), append=TRUE)
          

          添加相同圖形的第三張幻燈片,寬度和高度固定

          graph2ppt(file="ggplot2_plot.pptx", width=6, height=5, append=TRUE)
          

          禁用矢量化圖像導(dǎo)出

          graph2ppt(x=x, file=filen, vector.graphic=FALSE, width=9, aspectr=sqrt(2), append=TRUE)
          

          用圖填滿幻燈片

          graph2ppt(x=x, file=filen, margins=0, upscale=TRUE, append=TRUE)
          

          輸出矢量圖

          • graph2svg: 將當(dāng)前的R圖保存為SVG格式
          • graph2pdf: 將當(dāng)前的R圖保存為PDF格式
          • graph2eps: 將當(dāng)前的R圖保存為EPS格式

          函數(shù)參數(shù)解釋

          graph2vector(x=NULL, file="Rplot", fun=NULL, type="SVG",aspectr=NULL,
                  width=NULL, height=NULL, scaling=100,
                  font=ifelse(Sys.info()["sysname"]=="Windows",
                  "Arial","Helvetica")[[1]], bg="white", colormodel="rgb",
                  cairo=TRUE,fallback_resolution=600, ...)
          
          • fallback_resolution: dpi中的分辨率用于柵格化不支持的矢量圖形。
          #需運(yùn)行上面的ggplot2繪圖
          # Create a file name
          filen <- "output_filename" # or
          # filen <- paste("YOUR_DIR/ggplot")
          # There are 3 ways to use graph2vector():
          ### 1. Pass the plot as an object
          # 導(dǎo)出圖形對(duì)象
          graph2svg(x=x, file=filen, aspectr=2, font="Times New Roman",
                    height=5, bg="white")
          graph2pdf(x=x, file=filen, aspectr=2, font="Arial",
                    height=5,  bg="transparent")
          graph2eps(x=x, file=filen, aspectr=2, font="Arial",
                    height=5, bg="transparent")
          # 導(dǎo)出當(dāng)前預(yù)覽窗口呈現(xiàn)的圖
          ### 2. Get the plot from current screen device
          x
          graph2svg(file=filen, aspectr=2, font="Arial",
                    height=5, bg="transparent")
          graph2pdf(file=filen, aspectr=2, font="Times New Roman",
                    height=5, bg="white")
          graph2eps(file=filen, aspectr=2, font="Times New Roman",
                    height=5, bg="white")
          # 導(dǎo)出自定義函數(shù)輸出的一系列圖
          ### 3. Pass the plot as a function
          graph2svg(file=filen, fun=plot.fun, aspectr=2, font="Arial",
                    height=5, bg="transparent")
          graph2pdf(file=filen, fun=plot.fun, aspectr=2, font="Arial",
                    height=5, bg="transparent")
          graph2eps(file=filen, fun=plot.fun, aspectr=2, font="Arial",
                    height=5, bg="transparent")
          

          轉(zhuǎn)換3D圖形

          rgl2png: 將當(dāng)前的rgl 3D圖形保存為PNG格式。

          rgl2bitmap(file="Rplot", type=c("PNG"))
          
          # Create a file name
          filen <- tempfile("rgl") # or
          # filen <- paste("YOUR_DIR/rgl")
          # Generate a 3D plot using 'rgl'
          x=y=seq(-10, 10, length=20)
          z=outer(x, y, function(x, y) x^2 + y^2)
          rgl::persp3d(x, y, z, col='lightblue')
          # Save the plot as a png
          rgl2png(file=filen)
          # Note that omitting 'file' will save in current directory
          

          生成的3D圖形:

          將生成的3D圖形保存為PNG格式:

          輸出統(tǒng)計(jì)結(jié)果到表格 table2spreadsheet

          • table2excel: 導(dǎo)出統(tǒng)計(jì)輸出到Microsoft Office Excel/ LibreOffice Calc電子表格中的一個(gè)表.
          • table2csv:將統(tǒng)計(jì)輸出以CSV格式導(dǎo)出到表中(“,”表示值分隔,“。”表示小數(shù))
          • table2csv2: 將統(tǒng)計(jì)輸出以CSV格式導(dǎo)出到表中(“;”表示值分隔,”,”表示小數(shù))
          table2spreadsheet(x=NULL, file="Rtable", type=c("XLS", "CSV",
            "CSV2"), append=FALSE, sheetName="new sheet", digits=2,
            digitspvals=2, trim.pval=TRUE, add.rownames=FALSE, ...)
          
          • sheetName: 一個(gè)字符串,給出創(chuàng)建的新工作表的名稱(僅針對(duì)type==”XLS”)。它必須是惟一的(不區(qū)分大小寫),不受文件中任何現(xiàn)有工作表名稱的影響。
          • digits:除具有p值的列外,要顯示所有列的有效位數(shù)的數(shù)目。
          • digitspvals:具有p值的列要顯示的有效位數(shù)的數(shù)目。
          # Create a file name
          filen <- "table_aov" # or
          # filen <- paste("YOUR_DIR/table_aov")
          # Generate ANOVA output
          fit=aov(yield ~ block + N * P + K, data=npk) # 'npk' dataset from base 'datasets'
          x=summary(fit)
          # Save ANOVA table as a CSV
          ### Option 1: pass output as object
          # 輸出對(duì)象
          table2csv(x=x,file=filen, digits=1, digitspvals=3, add.rownames=TRUE)
          # 屏幕輸出導(dǎo)出到文件
          ### Option 2: get output from console
          summary(fit)
          table2csv(file=filen, digits=2, digitspvals=4, add.rownames=TRUE)
          # Save ANOVA table as an Excel
          # Without formatting of the worksheet
          x
          table2excel(file=filen, sheetName="aov_noformatting", digits=1, digitspvals=3, add.rownames=TRUE)
          # 更多參數(shù)
          # With formatting of the worksheet
          table2excel(x=x,file=filen, sheetName="aov_formated", append=TRUE, add.rownames=TRUE, fontName="Arial", fontSize=14, fontColour=rgb(0.15,0.3,0.75),  border=c("top", "bottom"), fgFill=rgb(0.9,0.9,0.9), halign="center", valign="center", textDecoration="italic")
          

          原始數(shù)據(jù)的表格:

          轉(zhuǎn)換格式之后的,在console中的數(shù)據(jù):


          文件(csv和excel)中表格數(shù)據(jù):

          導(dǎo)出為Word中的表,再也不用復(fù)制粘貼調(diào)格式了 table2office

          table2ppt: 導(dǎo)出統(tǒng)計(jì)輸出到Microsoft Office PowerPoint/ LibreOffice Impress演示文稿中的表

          table2doc: 將統(tǒng)計(jì)輸出導(dǎo)出到Microsoft Office Word/ LibreOffice Writer文檔中的表

          table2office(x=NULL, file="Rtable", type=c("PPT", "DOC"),
            append=FALSE, digits=2, digitspvals=2, trim.pval=TRUE,
            width=NULL, height=NULL, offx=1, offy=1,
            font=ifelse(Sys.info()["sysname"]=="Windows", "Arial",
            "Helvetica")[[1]], pointsize=12, add.rownames=FALSE)
          
          # Create a file name
          filen <- "table_aov"
          # filen <- paste("YOUR_DIR/table_aov")
          # Generate ANOVA output
          fit=aov(yield ~ block + N * P + K, data=npk) # 'npk' dataset from base 'datasets'
          # Save ANOVA table as a PPT
          ### Option 1: pass output as object
          x=summary(fit)
          table2ppt(x=x,file=filen, digits=1, digitspvals=3, add.rownames=TRUE)
          ### Option 2: get output from console
          summary(fit)
          table2ppt(x=x,file=filen, width=5, font="Times New Roman", pointsize=14, digits=4, digitspvals=1, append=TRUE, add.rownames=TRUE) # append table to previous slide
          # Save ANOVA table as a DOC file
          table2doc(x=x,file=filen, digits=1, digitspvals=3, add.rownames=TRUE)
          summary(fit)
          table2doc(file=filen, width=3.5, font="Times New Roman", pointsize=14,  digits=4, digitspvals=1, append=TRUE, add.rownames=TRUE) # append table at end of document
          

          將表格數(shù)據(jù)導(dǎo)出到ppt和word中:

          table2tex

          table2html: 導(dǎo)出統(tǒng)計(jì)輸出到HTML表。

          table2tex(x=NULL, file="Rtable", type="TEX", digits=2,
            digitspvals=2, trim.pval=TRUE, summary=FALSE, standAlone=TRUE,
            add.rownames=FALSE, ...)
          

          summary:是否匯總數(shù)據(jù)文件。

          standAlone:導(dǎo)出的Latex代碼應(yīng)該是獨(dú)立可編譯的,還是應(yīng)該粘貼到另一個(gè)文檔中。

          add.rownames:是否應(yīng)該將行名添加到表中(在第一列之前插入一列)。

          # Create a file name
          filen <- tempfile(pattern="table_aov") # or
          # filen <- paste("YOUR_DIR/table_aov")
          # Generate ANOVA output
          fit=aov(yield ~ block + N * P + K, data=npk) # 'npk' dataset from base 'datasets'
          x=summary(fit)
          # Export to Latex in standAlone format
          table2tex(x=x,file=filen,add.rownames=TRUE)
          # Export to Latex to paste in tex document
          summary(fit) # get output from the console
          table2tex(file=filen, standAlone=FALSE,add.rownames=TRUE)
          # Export to HTML
          table2html(x=x,file=filen) # or
          summary(fit) # get output from the console
          table2html(file=filen,add.rownames=TRUE)
          

          導(dǎo)出到html或tex中的表格數(shù)據(jù):


          R統(tǒng)計(jì)和作圖

          • Graphpad,經(jīng)典繪圖工具初學(xué)初探
          • 維恩(Venn)圖繪制工具大全 (在線+R包)
          • 在R中贊揚(yáng)下努力工作的你,獎(jiǎng)勵(lì)一份CheatShet
          • 別人的電子書,你的電子書,都在bookdown
          • R語(yǔ)言 - 入門環(huán)境Rstudio
          • R語(yǔ)言 - 熱圖繪制 (heatmap)
          • R語(yǔ)言 - 基礎(chǔ)概念和矩陣操作
          • R語(yǔ)言 - 熱圖簡(jiǎn)化
          • R語(yǔ)言 - 熱圖美化
          • R語(yǔ)言 - 線圖繪制
          • R語(yǔ)言 - 線圖一步法
          • R語(yǔ)言 - 箱線圖(小提琴圖、抖動(dòng)圖、區(qū)域散點(diǎn)圖)
          • R語(yǔ)言 - 箱線圖一步法
          • R語(yǔ)言 - 火山圖
          • R語(yǔ)言 - 富集分析泡泡圖
          • R語(yǔ)言 - 散點(diǎn)圖繪制
          • R語(yǔ)言 - 韋恩圖
          • R語(yǔ)言 - 柱狀圖
          • R語(yǔ)言 - 圖形設(shè)置中英字體
          • R語(yǔ)言 - 非參數(shù)法生存分析
          • R語(yǔ)言 - 繪制seq logo圖
          • WGCNA分析,簡(jiǎn)單全面的最新教程
          • psych +igraph:共表達(dá)網(wǎng)絡(luò)構(gòu)建
          • 一文學(xué)會(huì)網(wǎng)絡(luò)分析——Co-occurrence網(wǎng)絡(luò)圖在R中的實(shí)現(xiàn)
          • 一文看懂PCA主成分分析
          • 富集分析DotPlot,可以服
          • 基因共表達(dá)聚類分析和可視化
          • R中1010個(gè)熱圖繪制方法
          • 還在用PCA降維?快學(xué)學(xué)大牛最愛的t-SNE算法吧, 附Python/R代碼
          • 一個(gè)函數(shù)抓取代謝組學(xué)權(quán)威數(shù)據(jù)庫(kù)HMDB的所有表格數(shù)據(jù)
          • 文章用圖的修改和排版
          • network3D: 交互式桑基圖
          • network3D 交互式網(wǎng)絡(luò)生成
          • Seq logo 在線繪制工具——Weblogo
          • 生物AI插圖素材獲取和拼裝指導(dǎo)
          • ggplot2高效實(shí)用指南 (可視化腳本、工具、套路、配色)
          • 圖像處理R包magick學(xué)習(xí)筆記
          • SOM基因表達(dá)聚類分析初探
          • 利用gganimate可視化全球范圍R-Ladies(R社區(qū)性別多樣性組織)發(fā)展情況
          • 一分鐘繪制磷脂雙分子層:AI零基礎(chǔ)入門和基本圖形繪制
          • AI科研繪圖(二):模式圖的基本畫法
          • 你知道R中的賦值符號(hào)箭頭(<-)和等號(hào)(=)的區(qū)別嗎?
          • R語(yǔ)言可視化學(xué)習(xí)筆記之ggridges包
          • 利用ComplexHeatmap繪制熱圖(一)
          • ggplot2學(xué)習(xí)筆記之圖形排列
          • R包reshape2,輕松實(shí)現(xiàn)長(zhǎng)、寬數(shù)據(jù)表格轉(zhuǎn)換
          • 用R在地圖上繪制網(wǎng)絡(luò)圖的三種方法
          • PCA主成分分析實(shí)戰(zhàn)和可視化 附R代碼和測(cè)試數(shù)據(jù)
          • iTOL快速繪制顏值最高的進(jìn)化樹!
          • 12個(gè)ggplot2擴(kuò)展包幫你實(shí)現(xiàn)更強(qiáng)大的可視化
          • 編程模板-R語(yǔ)言腳本寫作:最簡(jiǎn)單的統(tǒng)計(jì)與繪圖,包安裝、命令行參數(shù)解析、文件讀取、表格和矢量圖輸出
          • R語(yǔ)言統(tǒng)計(jì)入門課程推薦——生物科學(xué)中的數(shù)據(jù)分析Data Analysis for the Life Sciences
          • 數(shù)據(jù)可視化基本套路總結(jié)
          • 你知道R中的賦值符號(hào)箭頭<-和等號(hào)=的區(qū)別嗎?
          • 使用dplyr進(jìn)行數(shù)據(jù)操作30例
          • 交集intersect、并集union、找不同setdiff
          • R包reshape2,輕松實(shí)現(xiàn)長(zhǎng)、寬數(shù)據(jù)表格轉(zhuǎn)換
          • 1數(shù)據(jù)類型(向量、數(shù)組、矩陣、 列表和數(shù)據(jù)框)
          • 2讀寫數(shù)據(jù)所需的主要函數(shù)、與外部環(huán)境交互
          • 3數(shù)據(jù)篩選——提取對(duì)象的子集
          • 4向量、矩陣的數(shù)學(xué)運(yùn)算
          • 5控制結(jié)構(gòu)
          • 6函數(shù)及作用域
          • 7認(rèn)識(shí)循環(huán)函數(shù)lapply和sapply
          • 8分解數(shù)據(jù)框split和查看對(duì)象str
          • 9模擬—隨機(jī)數(shù)、抽樣、線性模型
          • 1初識(shí)ggplot2繪制幾何對(duì)象
          • 2圖層的使用—基礎(chǔ)、加標(biāo)簽、注釋
          • 3工具箱—誤差線、加權(quán)數(shù)、展示數(shù)據(jù)分布
          • 4語(yǔ)法基礎(chǔ)
          • 5通過(guò)圖層構(gòu)建圖像
          • 6標(biāo)度、軸和圖例
          • 7定位-分面和坐標(biāo)系
          • 8主題設(shè)置、存儲(chǔ)導(dǎo)出
          • 9繪圖需要的數(shù)據(jù)整理技術(shù)
          • 創(chuàng)建屬于自己的調(diào)色板
          • 28個(gè)實(shí)用繪圖包,總有幾個(gè)適合你
          • 熱圖繪制
          • R做線性回歸
          • 繪圖相關(guān)系數(shù)矩陣corrplot
          • 相關(guān)矩陣可視化ggcorrplot
          • 繪制交互式圖形recharts
          • 交互式可視化CanvasXpress
          • 聚類分析factoextra
          • LDA分析、作圖及添加置信-ggord
          • 解決散點(diǎn)圖樣品標(biāo)簽重疊ggrepel
          • 添加P值或顯著性標(biāo)記ggpubr
          • Alpha多樣性稀釋曲線rarefraction curve
          • 堆疊柱狀圖各成分連線畫法:突出組間變化
          • 沖擊圖展示組間時(shí)間序列變化ggalluvial
          • 桑基圖riverplot
          • 微生物環(huán)境因子分析ggvegan
          • 五彩進(jìn)化樹與熱圖更配ggtree
          • 多元回歸樹分析mvpart
          • 隨機(jī)森林randomForest 分類Classification 回歸Regression
          • 加權(quán)基因共表達(dá)網(wǎng)絡(luò)分析WGCNA
          • circlize包繪制circos-plot
          • R語(yǔ)言搭建炫酷的線上博客系統(tǒng)
          • 28個(gè)實(shí)用繪圖包,總有幾個(gè)適合你
          • 熱圖繪制
          • R做線性回歸
          • 繪圖相關(guān)系數(shù)矩陣corrplot
          • 相關(guān)矩陣可視化ggcorrplot
          • 繪制交互式圖形recharts
          • 交互式可視化CanvasXpress
          • 聚類分析factoextra
          • LDA分析、作圖及添加置信-ggord
          • 解決散點(diǎn)圖樣品標(biāo)簽重疊ggrepel
          • 添加P值或顯著性標(biāo)記ggpubr
          • Alpha多樣性稀釋曲線rarefraction curve
          • 堆疊柱狀圖各成分連線畫法:突出組間變化
          • 沖擊圖展示組間時(shí)間序列變化ggalluvial
          • 桑基圖riverplot
          • 微生物環(huán)境因子分析ggvegan
          • 五彩進(jìn)化樹與熱圖更配ggtree
          • 多元回歸樹分析mvpart
          • 隨機(jī)森林randomForest 分類Classification 回歸Regression
          • 加權(quán)基因共表達(dá)網(wǎng)絡(luò)分析WGCNA
          • circlize包繪制circos-plot
          • R語(yǔ)言搭建炫酷的線上博客系統(tǒng)
          • 維恩(Venn)圖繪制工具大全 (在線+R包)
          • R包c(diǎn)irclize:柱狀圖用膩了?試試好看的弦狀圖
          • 獲取pheatmap聚類后和標(biāo)準(zhǔn)化后的結(jié)果
          • 增強(qiáng)火山圖,要不要試一下?
          • 一個(gè)震撼的交互型3D可視化R包 - 可直接轉(zhuǎn)ggplot2圖為3D
          • 贈(zèng)你一只金色的眼 - 富集分析和表達(dá)數(shù)據(jù)可視化
          • 是Excel的圖,不!是R的圖
          • 道友,來(lái)Rstudio里面看動(dòng)畫了
          • 用了這么多年的PCA可視化竟然是錯(cuò)的!!!

          主站蜘蛛池模板: 亚洲第一区视频在线观看| 国产精品一区二区三区久久| 在线免费视频一区| 亚洲一区精彩视频| 亚洲天堂一区二区三区| 国产日韩一区二区三免费高清| 国产精品综合一区二区三区| 日本一区视频在线播放| 精品成人av一区二区三区| 国产伦精品一区二区三区四区| 一区二区三区四区视频在线| 国产伦精品一区二区三区| 亚洲电影唐人社一区二区| 日本一区二区三区高清| 日韩人妻精品一区二区三区视频| 色噜噜狠狠一区二区三区| 欧洲精品一区二区三区| 亚洲一区无码中文字幕| 精品国产鲁一鲁一区二区| 国产综合无码一区二区色蜜蜜| 亚洲午夜福利AV一区二区无码| 欲色aV无码一区二区人妻| 一本岛一区在线观看不卡| 日韩毛片基地一区二区三区| 国产麻豆媒一区一区二区三区| 日本在线一区二区| 国产一区二区三区免费视频 | 色窝窝无码一区二区三区成人网站| 在线观看国产一区二三区| 亚洲av无码天堂一区二区三区| 搡老熟女老女人一区二区| 日韩精品一区二区三区在线观看| 无码一区二区三区老色鬼| 国产人妖在线观看一区二区| 无码国产精品一区二区免费模式 | 久久国产精品一区| 91国偷自产一区二区三区| 国产综合无码一区二区辣椒| 国产精品第一区第27页| 好吊妞视频一区二区| 亚洲国产国产综合一区首页|