Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <!DOCTYPE html>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>
  <style type="text/css">
    .uni-flex {
      display: flex;
      flex-direction: row;

    .uni-flex-item {
      flex: 1;
    .menu-item {
      width: 200px;
    .border-gray {
      border: solid 1px #DEDEDE;
<div class="uni-flex">
  <div class="menu-item">
      <li draggable="true" id='name'><span>【姓名】</span></li>
  <div class="uni-flex-item border-gray" id="x-spreadsheet-demo"></div>


document.addEventListener('DOMContentLoaded', (evtAll) => {

  const xs = new x_spreadsheet("#x-spreadsheet-demo", {
    mode: 'edit', // edit | read
    showToolbar: true,
    showGrid: true,
    showContextmenu: true,
    view: {
      height: () => document.documentElement.clientHeight,
      width: () => document.documentElement.clientWidth - 200,
    row: {
      len: 100,
      height: 25,
    col: {
      len: 26,
      width: 100,
      indexWidth: 60,
      minWidth: 60,
    style: {
      bgcolor: '#ffffff',
      align: 'left',
      valign: 'middle',
      textwrap: false,
      strike: false,
      underline: false,
      color: '#0a0a0a',
      font: {
        name: 'Helvetica',
        size: 10,
        bold: false,
        italic: false,
  .loadData({}) // load data
  .change(data => {
    // save data to db

  // data validation

  // 测试xs的方法
  setTimeout(() => {
    console.log('',, 310));
  }, 2000);

  function onSelected(event) {
    // = 'background-color: blue';

  document.getElementById('name').addEventListener('click', onSelected, false);

   * 拖拽开始
   * @param {DragEvent} event事件对象
  function onDragStart(event) {
    if(! || !event.dataTransfer) {

    let text =;
    let children =[0].innerText;
    console.log('from text:', text, 'children:', children);
    // 传送的数据
    event.dataTransfer.setData('key', 'name');
    // 传送的数据
    event.dataTransfer.setData('value', text);

  document.getElementById('name').addEventListener('dragstart', onDragStart, false);

  // 拖动事件
  function onDragOver(event) {

  // 松开拖放
  function onDrop(event) {

    const target = event.currentTarget;
    if(!target || !event.dataTransfer) {

    let key = event.dataTransfer.getData('key');
    let value = event.dataTransfer.getData('value');
    // 目标位置
    var targetPosition = getTargetPosition(event);
     * 通过鼠标目标位置的x、y坐标,获取所在的行下表、列下标
     * ri 行下标
     * ci 列下标
    const { ri, ci } =, targetPosition.y);
    xs.cellText(ri, ci, `${key}:${value}`).reRender();

  // 监听事件
  document.getElementById('x-spreadsheet-demo').addEventListener('dragover', onDragOver, false);
  document.getElementById('x-spreadsheet-demo').addEventListener('drop', onDrop, false);

  // 获取拖拽松开鼠标时,目标位置的x、y坐标
  function getTargetPosition(event) {
    const canvas = document.querySelector('.x-spreadsheet-table');
    const x = event.pageX - canvas.getBoundingClientRect().left;
    const y = event.pageY - canvas.getBoundingClientRect().top;
    return { x: x, y: y };