Excel将多个列vba放入一个单元格中

时间:2016-07-07 03:59:16

标签: excel vba

createNewWidget(e) {
  e.preventDefault()

  var form = e.target

  var width =  form.elements.width.value
  var title = form.elements.title.value
  var description = form.elements.description.value

  this.props.updateWidgetConfig({
    width,
    title,
    description,
  })
},

我想要这样的输出:

var classNames = require('classnames')
var React = require('react')
var ReactDOM = require('react-dom')
var uuid = require('uuid')

var Widget = React.createClass({
  render() {
    var {widget} = this.props
    var widgetClasses = classNames('widget', widget.width)
    return <div className={widgetClasses}>
      <header className="widget-header">
        <h3>{widget.title}</h3>
        <p>{widget.description}</p>
      </header>
      <ul>
        <li>Lorem ipsum</li>
      </ul>
      <ul>
        <li>Dolor sit</li>
      </ul>
    </div>
  }
})

var WidgetsContainer = React.createClass({
  render() {
    return <div className="widgetsContainer">
      {this.props.data.map(widget =>
        <Widget key={widget.id} widget={widget}/>
      )}
    </div>
  }
})

var Dashboard = React.createClass({
  getInitialState() {
    return {
      data: []
    }
  },
  handleWidgetConfig(widget) {
    this.setState({
      data: [
        ...this.state.data,
        {id: uuid.v4(), ...widget},
      ]
    })
  },
  render() {
    return <div className="dashboard-content">
     <CreateWidgetDropdown updateWidgetConfig={this.handleWidgetConfig} />
     <WidgetsContainer data={this.state.data} />
    </div>
  }
})

var CreateWidgetDropdown = React.createClass({
  createNewWidget(e) {
    e.preventDefault()

    var form = e.target

    var width =  form.elements.width.value
    var title = form.elements.title.value
    var description = form.elements.description.value

    this.props.updateWidgetConfig({
      width,
      title,
      description,
    })
  },
  render() {
    return <div className="page-dropdown">
      <div className="page-dropdown-header">
        <h2 className="wrapper">Add a Widget</h2>
      </div>
      <div id="page-dropdown-content">
        <form className="page-dropdown-form" onSubmit={this.createNewWidget}>
          <div className="choose-widget-type">
            <h3>Choose a Widget Type</h3>
            <div className="widget-type table">
              <h4>Table</h4>
              <div className="widget-type-icon">
                <img src="" alt="" />
              </div>
              <ul className="widgetWidth">
                <li>
                  <label>
                    1/3 Width
                    {' '}
                    <input name="width" type="radio" value="1/3 Width" defaultChecked/>
                  </label>
                </li>
               <li>
                  <label>
                    2/3 Width
                    {' '}
                    <input name="width" type="radio" value="2/3 Width" />
                  </label>
                </li>
                <li>
                  <label>
                    Full Width
                    {' '}
                    <input name="width" type="radio" value="Full Width" />
                  </label>
                </li>
              </ul>
            </div>

            <div className="create-widget-header">
              <h3>Widget Header (Optional)</h3>
              <label>
                Widget Title (30 characters max)
                {' '}
                <input type="text" name="title" required />
              </label>
              <label>
                Widget Description (50 characters max)
                {' '}
                <textarea name="description"></textarea>
              </label>
            </div>
            <button type="submit">Add Widget</button>
            <button type="reset">Cancel</button>
          </div>
        </form>
      </div>
    </div>
  }
})

ReactDOM.render(<Dashboard />, document.getElementById('app'))

请帮帮我

1 个答案:

答案 0 :(得分:1)

试试这个公式:

=IFERROR(INDEX($A$1:$C$4,MOD(ROW()-1,4)+1,INT((ROW()-1)/4)+1),"")

并根据需要拖放/复制。

enter image description here

VBA解决方案:

Sub RowsToColumn()
    Dim dict As Object
    Dim lastRow As Long, lastColumn As Long, cnt As Long
    Dim myRng As Range

    Set dict = CreateObject("Scripting.Dictionary")

    'get last row and column with data
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    lastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
    'set your range here
    'Set myRng = Range("A1:C4")
    Set myRng = Range(Cells(1, 1), Cells(lastRow, lastColumn))

    cnt = 1
    'put cell value in dictionary
    For Each col In myRng.Columns
        For Each cel In col.Cells
            dict.Add cel.Value, cnt
            cnt = cnt + 1
        Next cel
    Next col
    'display values in dictionary
    Range("E1").Resize(dict.Count) = Application.Transpose(dict.keys)
End Sub