This project is read-only.

How to Insert a Column in a .xls or .xlsx file?

Dec 11, 2013 at 8:37 AM
I know there's some way to insert rows. But how to insert columns?
static void InsertRows(ref HSSFSheet sheet1, int fromRowIndex, int rowCount)
        {
            sheet1.ShiftRows(fromRowIndex, sheet1.LastRowNum, rowCount, true, false, true);

            for (int rowIndex = fromRowIndex; rowIndex < fromRowIndex + rowCount; rowIndex++)
            {
                Row rowSource = sheet1.GetRow(rowIndex + rowCount);
                Row rowInsert = sheet1.CreateRow(rowIndex);
                rowInsert.Height = rowSource.Height;
                for (int colIndex = 0; colIndex < rowSource.LastCellNum; colIndex++)
                {
                    Cell cellSource = rowSource.GetCell(colIndex);
                    Cell cellInsert = rowInsert.CreateCell(colIndex);
                    if (cellSource != null)
                    {
                        cellInsert.CellStyle = cellSource.CellStyle;
                    }
                }
            }
        }
Dec 19, 2013 at 5:34 PM
There is no native API to do that. But you can try to figure out by your own code.