如何在EXCEL的数据中导入到我自己设定的EXCEL模板中!?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在EXCEL的数据中导入到我自己设定的EXCEL模板中!?相关的知识,希望对你有一定的参考价值。

RT。。。
我EXCEL有一组数据~
另外我在EXCEL中设定了摸板。。
如何用VBA将数据导入!?

参考技术A Option Explicit

Sub 生成标签()
Dim R As Long
Dim i As Long
Dim sht As Worksheet
Dim shtFrom As Worksheet
Dim shtMB As Worksheet
Dim toBK As Excel.Workbook
Dim FoundMB As Boolean
Dim FoundData As Boolean
For i = 1 To ThisWorkbook.Worksheets.Count
If ThisWorkbook.Worksheets(i).Name = "模板" Then FoundMB = True
If ThisWorkbook.Worksheets(i).Name = "数据" Then FoundData = True
Next

If FoundMB = False Or FoundData = False Then
MsgBox "找不到[模板]或[数据]工作表"
GoTo Exit_Sub
End If
Set shtMB = ThisWorkbook.Worksheets("模板")
Set shtFrom = ThisWorkbook.Worksheets("数据")
R = shtFrom.Range("A65536").End(xlUp).Row
Application.ScreenUpdating = False
Set toBK = Application.Workbooks.Add
For i = 2 To R Step 3
shtMB.Copy , toBK.Worksheets(toBK.Worksheets.Count)
Set sht = toBK.Worksheets(toBK.Worksheets.Count)
With sht
.Range("c1") = "'" & shtFrom.Cells(i, 1)
.Range("C3") = shtFrom.Cells(i, 2)
.Range("g5") = shtFrom.Cells(i, 3)
.Range("c19") = "'" & shtFrom.Cells(i + 1, 1)
.Range("C21") = shtFrom.Cells(i + 1, 2)
.Range("g23") = shtFrom.Cells(i + 1, 3)
.Range("c37") = "'" & shtFrom.Cells(i + 2, 1)
.Range("C39") = shtFrom.Cells(i + 2, 2)
.Range("g41") = shtFrom.Cells(i + 2, 3)

End With
sht.Name = Right(shtFrom.Cells(i, 1), 5) & "-" & Right(shtFrom.Cells(i + 1, 1), 5)
Next
On Error Resume Next
Application.ScreenUpdating = False
For i = 1 To 3
toBK.Worksheets("Sheet" & i).Visible = xlSheetVeryHidden
Next
Application.ScreenUpdating = True
ThisWorkbook.Worksheets(1).Select
'shtFrom.Select
Application.ScreenUpdating = True
Exit_Sub:
Set toBK = Nothing
End Sub本回答被提问者采纳

如何将数据从闪亮的应用程序写入exce / csv文件?恰好我想将股票价格值的值写入excel / csv文件

我想将股票价格的值写入excel / csv文件。但是无法这样做。显示以下错误代码:如果没有活动的响应上下文,则不允许进行操作。 (您试图做只能从反应式表达式或观察器内部完成的操作。)。当我使用反应性数据(dataInput)时,错误消息显示为“无法强制将类'c(“ reactiveExpr”,“ reactive”))强制到data.frame

此代码附在此处。:

加载程序包----

library(shiny)
library(quantmod)
#edited the code.this can be run directly

# User interface ----
ui <- fluidPage(
  titlePanel("stockVis"),

  sidebarLayout(
    sidebarPanel(
      helpText("Select a stock to examine.

        Information will be collected from Yahoo finance."),
      textInput("symb", "Symbol", "SPY"),

      dateRangeInput("dates",
                     "Date range",
                     start = "2013-01-01",
                     end = as.character(Sys.Date())),

      br(),
      br(),

      checkboxInput("log", "Plot y axis on log scale",
                    value = FALSE)

      #checkboxInput("adjust",
      #"Adjust prices for inflation", value = FALSE)
    ),

    mainPanel(plotOutput("plot"), tableOutput("view")))



)


# Server logic
server <- function(input, output) 

  dataInput <- reactive(
    getSymbols(input$symb, src = "yahoo",
               from = input$dates[1],
               to = input$dates[2],
               auto.assign = FALSE)


  ) Blockquote
  output$plot <- renderPlot(

    chartSeries(dataInput(), theme = chartTheme("white"),
                type = "line", log.scale = input$log, TA = NULL)
  )

  output$view <- renderTable((dataInput() )
  , include.rownames = TRUE)
  #trying to export the data
  write.csv(dataInput(),row.names = TRUE)

`enter code here`

# Run the app
shinyApp(ui, server)
答案

在被动上下文中,一旦股票代码开始变化,它将尝试在运行Shiny应用程序后立即执行代码。要允许文件仅在用户准备就绪时才写入,请将“反应性”更改为“观察事件”。添加了“运行”按钮以使其工作。复制并粘贴下面的代码。

顺便说一下,'write.csv'命令中省略了'file =',该命令将csv文件滚动到控制台。

library(shiny)
library(quantmod)
#edited the code.this can be run directly

# User interface ----
ui <- fluidPage(
  titlePanel("stockVis"),

  sidebarLayout(
    sidebarPanel(
      helpText("Select a stock to examine.

        Information will be collected from Yahoo finance."),
      textInput("symb", "Symbol", "SPY"),

      dateRangeInput("dates",
                     "Date range",
                     start = "2013-01-01",
                     end = as.character(Sys.Date())),

      br(),
      br(),

      checkboxInput("log", "Plot y axis on log scale",
                    value = FALSE),

      #checkboxInput("adjust",
      #"Adjust prices for inflation", value = FALSE),
      actionButton(inputId = "run",label="Run"),
    ),

    mainPanel(plotOutput("plot"), tableOutput("view")))

)

# Server logic
server <- function(input, output) 

  dataInput <- function() 
    getSymbols(input$symb, src = "yahoo",
               from = input$dates[1],
               to = input$dates[2],
               auto.assign = FALSE)
  

  observeEvent (input$run, 

   output$plot <- renderPlot(

    chartSeries(dataInput(), theme = chartTheme("white"),
                type = "line", log.scale = input$log, TA = NULL)
    )

    output$view <- renderTable((dataInput() )
    , include.rownames = TRUE)
    #trying to export the data
    write.csv(dataInput(),row.names = TRUE)

  )

# Run the app

shinyApp(ui, server)

以上是关于如何在EXCEL的数据中导入到我自己设定的EXCEL模板中!?的主要内容,如果未能解决你的问题,请参考以下文章

怎么在navicat 中导入excel 表格数据

DELPHI中导入Excel时,存在格式问题,怎么解决?

如何将数据从闪亮的应用程序写入exce / csv文件?恰好我想将股票价格值的值写入excel / csv文件

如何把EXCEL整理好的数据表直接导入到MYSQL中

如何在数据库中导入excel文件内的数据

如何在 Laravel 中导入具有各种模型(和子数据/模型)的单个 excel 文件/工作表?