如何使用openxlsx选择性地将边框应用于现有的xlsx

时间:2018-05-30 02:30:45

标签: openxlsx

目标是使用openxlsx将边框应用于表的某些部分。接下来,我将展示所需的输出,以不同于所需的方式构建:打印表格的各个部分并在每个步骤中对其进行格式化:

library(openxlsx)
library(tidyverse)
set.seed(15)
###create workbook
wb <- createWorkbook()
addWorksheet(wb, "test2")
#Sample a portion of iris to make it short
iris%>%dplyr::sample_n(15)->sample_iris

#split according to Species
sample_iris%>%filter(Species %in% "setosa")->p1
sample_iris%>%filter(Species %in% "versicolor")->p2
sample_iris%>%filter(Species %in% "virginica")->p3

##write each part and apply borders
writeData(wb, 1,p1, startRow = 1, startCol = 1,borders = "surrounding",borderStyle="thick")
writeData(wb, 1,p2, startRow = 1+dim(p1)[1], startCol = 1,borders = "surrounding",colNames =F,borderStyle="thick")
writeData(wb, 1,p3, startRow = 1+dim(p1)[1]+dim(p2)[1], startCol = 1,borders = "surrounding",colNames =F,borderStyle="thick")
saveWorkbook(wb, "test2.xlsx", overwrite = TRUE)

所以“test2.xlsx”是所需的输出。问题是如何通过生成文件来实现它,而不是修改现有文件。我的意思是,如果文件“test1.xlsx”是由

创建的
write.xlsx(sample_iris, file = "test1.xlsx")

那么,如何根据需要在现有文件上应用边框? 感谢您的任何指南

1 个答案:

答案 0 :(得分:0)

接下来是执行任务的代码:

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

const API_KEY = "9f64caf0";

class App extends Component {
  constructor(props){
    super(props);
    this.state={
      movies:[],
    }
  }
   componentDidMount(){
     const imdb = require("imdb-api");

      imdb
        .search({ title: "Game Of Thrones" }, { apiKey: API_KEY })
        .then((movies)=>{this.setState({movies})})

        console.log(this.state.movies)

      }

  render() {
      return (
      <div >

      </div>
    );
  }
}

export default App;

我感谢对此提出任何意见。