Setting Column Widths Corrupts Spreadsheet

I'm working with Open XML for the first time and I am astonished at how complicated it is.  The Excel object model was complicated, but it seems simple by comparison.  I'm about ready to give up and look for a different solution, but I'll try posting
this question here and see if I can get any simple answers. 
I have an ASP.NET MVC web page and I want to let my user download a spreadsheet with data from the database.  I can get some data to appear in the downloaded spreadsheet, but when I tried to set the column widths in Open XML it started given me file
validation errors and none of the data appears, and the column widths are not set.  It's just a blank spreadsheet.  This is the error it displays:
Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.
Replaced Part: /xl/worksheets/sheet.xml part with XML error.  Load error. Line 1, column 211.
Here is the test code that has only one cell loaded with the value Test 4.  It appears when I don't load the Columns object.  It disappears with this error when I try to load the Columns object.  Here is my code:
private void CreatePartsTest()
document = SpreadsheetDocument.Create(moMemoryStream, SpreadsheetDocumentType.Workbook);
WorkbookPart workbookPart = document.AddWorkbookPart();
Workbook workbook = new Workbook();
workbookPart.Workbook = workbook;
WorkbookStylesPart workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>("rIdStyles");
Stylesheet stylesheet = new Stylesheet();
workbookStylesPart.Stylesheet = stylesheet;
WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>("TestID");
Worksheet worksheet = new Worksheet();
Columns cs = new Columns();
Column c = new Column()
Min = (UInt32Value)1U,
Max = (UInt32Value)1U,
Width = 44.33203125D,
CustomWidth = true
cs.Append(c);
//worksheetPart.Worksheet.Append(cs);
worksheet.Append(cs);
// LoadColumns(ref worksheet, oGridColumns);
//worksheet.Append(new Columns(new Column() { Min = (uint)1U, Max = (uint)1U, Width = 24 }));
SheetViews sheetViews = new SheetViews();
SheetView sheetView = new SheetView() { TabSelected = true, WorkbookViewId = (UInt32Value)0U };
sheetViews.Append(sheetView);
SheetData sheetData1 = new SheetData();
Row row1 = new Row() { RowIndex = (UInt32Value)1U };
sheetData1.Append(row1);
worksheet.Append(sheetViews);
worksheet.Append(sheetData1);
worksheetPart.Worksheet = worksheet;
Sheet sheet = new Sheet();
sheet.Name = "Test";
sheet.SheetId = (uint)1;
sheet.Id = "TestID";
Sheets sheets = new Sheets();
sheets.Append(sheet);
workbook.Append(sheets);
//oSpreadSheet.WorkbookPart.Workbook.Save();
wbPart = document.WorkbookPart;
MCSD .NET developer in Dallas, Texas

Here is the test code that has only one cell loaded with the value Test 4.  It appears when I don't load the Columns object.  It disappears with this error when I try to load the Columns object. 
Hi DallasSteve,
How did you load the cells and why? Could you please post the details of the method "LoadColumns(ref worksheet, oGridColumns)"?
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • Setting column width in a command-line program

    Is there a way to send data to the screen in a command-line Java program that will be formatted as a number
    of columns with a set column width? I am looking for something similar to the C++ setw() I/O manipulator
    used in cout.
    Thanks,
    Steve

    If you go to: http://java.sun.com/docs/books/tutorial/essential/io/writingFiltered.html
    it will show you how to subclass a filtered output stream and add your own formatting methods.Then you can chain your new class to System.out
    like this:
    YourFilteredStream yfs = new YourFilteredStream(System.out); .
    Then:
    yfs.yourNewMethod(); goes directly to system out in the new format.

  • Set Column width in query (not using SQL*Plus)

    How can I Set Column width in query
    I understand you can set column width using
    column col1 FORMAT A5
    select col1 from table1;But this only works in SQL*Plus
    I want to be able to do this in a regular SQL query window (not in SQL*Plus), how can I do it.....
    I am using a 'SQL window' in PL/SQL Developer IDE
    and when I use this syntax it says:
    ORA-00900: Invalid SQL statement
    Any suggestions are appreciated...
    thanks,
    M.

    Did you try using RPAD or LPAD functions? They fill the unfilled part of a string with character you provide... either on right or left side depending on what function you use.
    e.g.
    SELECT RPAD('Smith', 10, ' ') Name FROM dual;http://www.adp-gmbh.ch/ora/sql/rpad.html
    Edited by: Zaafran Ahmed on Nov 10, 2010 11:50 AM

  • How to set column widths in tables for selected table only, not globally throughout document?

    I've been utilizing the below script (thank you so much Ramkumar. P!) to set column widths throughout a sizable InDesign book with tables on every page and it is truly a time saver. At this point in time, I have three versions of it because there are different column widths throughout the book. Is it possible to augment the script to run only on a selected text frame (containing a table)? If so, would someone be kind enough to share the augmented script with me? I've been trying to figure out this seemingly simple change through trial and error with no success as yet. I realize this is a totally newbie request and I'm entirely at the mercy of the kindness of the Javascript gods that contribute within this forum. Seeing that in a different post related to this script, one such guru responded to a request as simple as "Where do I put the scripts in InDesign" gave me enough courage to ask for some help! Thank you in advance to anyone willing to provide a solution.
      var myDoc = app.activeDocument;
         var myWidths = [100, 100, 150, 150];
         for(var T=0; T < myDoc.textFrames.length; T++){
             for(var i=0; i < myDoc.textFrames[T].tables.length; i++){
                 for(var j=0; j < myWidths.length; j++){
                     myDoc.textFrames[T].tables[i].columns[j].width = myWidths[j];
         alert("Table width updated successfully...");

    Hello all
    I have the same problem in that I'm not a scripting person, but was able to get the above script working without problem, and it does set irregular table column widths perfectly, so thanks to Ramkumar. P for that.
    BUT, it changes the column width for ALL tables in the document, whereas I would like to just target the selected table.
    Any ideas as to how I might amend this script to achieve this?
    Thx, Christian

  • How to set column width in alvgrid

    hi
    how to set column width in alvgrid.
    thanks.

    Hi,
    Check this,
    REPORT  ztest.
    DATA: BEGIN OF i_scarr_tab OCCURS 0.
            INCLUDE STRUCTURE  scarr.
    DATA: END OF i_scarr_tab.
    DATA: i_scarr LIKE TABLE OF i_scarr_tab WITH HEADER LINE,
          w_scarr LIKE LINE OF i_scarr_tab.
    DATA: o_grid      TYPE REF TO cl_gui_alv_grid,
          o_container TYPE REF TO cl_gui_custom_container.
    DATA: lt_fcat     TYPE lvc_t_fcat,
          ls_layo     TYPE lvc_s_layo,
          ls_sort     TYPE lvc_s_sort,
          lt_sort     TYPE lvc_t_sort,
          ls_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
    START-OF-SELECTION.
      CALL SCREEN 9000.
    *&      Module  status_9000  OUTPUT
          text
    MODULE status_9000 OUTPUT.
      SET PF-STATUS '9000'.
      SET TITLEBAR '9000'.
    ENDMODULE.                 " status_9000  OUTPUT
    *&      Module  user_command_9000  INPUT
          text
    MODULE user_command_9000 INPUT.
      CASE sy-ucomm .
        WHEN 'BACK' OR 'EXIT'.
          SET SCREEN 0.
          LEAVE SCREEN.
      ENDCASE.
    ENDMODULE.                 " user_command_9000  INPUT
    *&      Module  init_9000  OUTPUT
          text
    MODULE init_9000 OUTPUT.
      IF o_container IS INITIAL.
        SELECT * FROM scarr INTO CORRESPONDING FIELDS OF TABLE
           i_scarr UP TO 100 ROWS.
        IF cl_gui_alv_grid=>offline( ) IS INITIAL.
    Create a custom container control for ALV Control
          CREATE OBJECT o_container
              EXPORTING
                  container_name = 'CONTROL'.
    Create a ALV Control
          CREATE OBJECT o_grid
              EXPORTING i_parent = o_container.
          PERFORM build_field_catalgue.
          ls_layo-sel_mode = 'A'.
          CALL METHOD o_grid->set_table_for_first_display
            EXPORTING
              i_save          = 'A'
              i_default       = 'X'
              is_layout       = ls_layo
            CHANGING
              it_outtab       = i_scarr[]
              it_fieldcatalog = lt_fcat
              it_sort         = lt_sort[].
        ENDIF.
      ENDIF.
    ENDMODULE.                 " init_9000  OUTPUT
    *&      Form  build_field_catalgue
          text
    -->  p1        text
    <--  p2        text
    FORM build_field_catalgue .
      DATA: ls_fcat TYPE lvc_s_fcat.
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          i_program_name         = sy-cprog
          i_internal_tabname     = 'I_SCARR_TAB'
          i_structure_name       = 'SCARR'
         i_client_never_display = 'X'
        CHANGING
          ct_fieldcat            = ls_fieldcat[]
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
      IF sy-subrc <> 0.
        MESSAGE 'FCAT Error' TYPE 'I'.
        EXIT.
      ENDIF.
      LOOP AT  ls_fieldcat.
        CLEAR ls_fcat.
        ls_fcat-fieldname = ls_fieldcat-fieldname.     "Fieldname
        ls_fcat-ref_table = ls_fieldcat-tabname.       "DDIC ref struct
        ls_fcat-inttype   = ls_fieldcat-inttype.       "Data type
        ls_fcat-outputlen = ls_fieldcat-outputlen.     "Column width
        ls_fcat-coltext   = ls_fieldcat-seltext_m.     "Column Header
        ls_fcat-seltext   = ls_fieldcat-seltext_m.     "Column Desc
        ls_fcat-ref_field = ls_fieldcat-ref_fieldname. "Reference field
        ls_fcat-ref_table = ls_fieldcat-ref_tabname.   "Reference table
        CASE  ls_fieldcat-fieldname.
          WHEN 'LUGGWEIGHT' OR 'FORCURAM'.
            ls_fcat-edit      = 'X'.
            ls_fcat-do_sum    = 'X'.
          WHEN 'URL'.
            ls_fcat-no_out = 'X'.
          WHEN OTHERS.
            ls_fcat-edit      = ' '.
            ls_fcat-do_sum    = ' '.
        ENDCASE.
        APPEND ls_fcat TO lt_fcat.
      ENDLOOP.
    ENDFORM.                    " build_field_catalgue
    check the programs bcalv_grid*.
    check this link for more detailed example.
    http://www.supinfo-projects.com/fr/2005/alv_display_fr/2/
    Regards
    Sruthi

  • How can I set column width in JTable?

    How can I set column width in JTable?

    Also, read the JTable API before posting questions. You will find a link to the Swing tutorial on "How to Use Tables", which contains an example of doing exactly this.

  • Dynamically setting column width doesn't work all the time

    I wanted to dynamically set the width of a column in a JTable to be half of the width of a another column. This should happen whenever the frame is resized. But somehow I need to tell this twice to Java. If I don't then sometimes the column width isn't set new.
    Is this a Java bug or what?
    public void componentResized(ComponentEvent ce)
         try
              ref.table.getColumn(ref.rsmd.getColumnLabel(5)).setMaxWidth(ref.table.getColumn(ref.rsmd.getColumnLabel(1)).getWidth() / 2);
              ref.table.getColumn(ref.rsmd.getColumnLabel(5)).setMinWidth(ref.table.getColumn(ref.rsmd.getColumnLabel(1)).getWidth() / 2);
              // Again, or it won't work:
              ref.table.getColumn(ref.rsmd.getColumnLabel(5)).setMaxWidth(ref.table.getColumn(ref.rsmd.getColumnLabel(1)).getWidth() / 2);
              ref.table.getColumn(ref.rsmd.getColumnLabel(5)).setMinWidth(ref.table.getColumn(ref.rsmd.getColumnLabel(1)).getWidth() / 2);
         catch(SQLException e)
    }

    Is it possible that your call to
    ref.table.getColumn(ref.rsmd.getColumnLabel(5)).setMinWidth(ref.table.getColumn(ref.rsmd.getColumnLabel(1)).getWidth() / 2);
    is altering the response created by
    ref.table.getColumn(ref.rsmd.getColumnLabel(5)).setMaxWidth(ref.table.getColumn(ref.rsmd.getColumnLabel(1)).getWidth() / 2);
    ? Have you tried calling them once but in the other order? Or just calling the "setMaxWidth" call twice and leaving out the second "setMinWidth"?
    Good luck... :)

  • How do I set Column Width in table displayed - have tried everything :-(

    Hi,
    I'm using Jdev 10.1.2, adf bc and jsp's.
    Simple problem, driving me nuts. In my app i display a number of different view objects in a number of jsp's. i want to set the width of the columns so that the info (if large) in each field will stay on one line. i.e. it wont continue onto the next line and take up two rows.
    i have tried setting the width property of the <th> & <td>, setting the disply width property in the entity object editor and the view object editor, nothing makes a bit of difference to how the column is displayed.
    this results in the tables looking messy and squised, which is totally unsatisfactory.
    so if anyone could shed any light on the subject, i would be most grateful.
    Thanks in advance......

    hi Newbe,
    if you set the option noWrap="true" on the column the text will not be wrapped;
    <af:column noWrap="true" sortable="false" headerText="col5">
    <af:outputText value="#{row.col5}"/>
    </af:column>
    Good luck
    Luc Bors

  • How do I set column widths in read/write rules?

    Hello structure experts,
    I am reading a set of DITA files into a specific FM template format, and there is one detail I cannot get to work properly. It should be possible to define column widths in a table, even if the DITA file does not include that information. But the Structure Application Developer Reference does not give the information on which string to pass to the column widths fm property. Does anyone out there have experience in doing this ?
    Thanks
    Jang

    Got it !!!
    Turned out to be simple, but the info was more or less hidden in the Dev Ref Guide: I had already put the "fm property column widths is value " line in but did not know the syntax for the values. Turns out you need to delimit the values by spaces, not commas. The parser does not give ANY useful information about this, just mentions 'syntax error near somewhere' or completely ignores the values you specify.
    This is how the rule for my DITA properties element now works out:
    element "properties" {
      is fm table element;
      fm property columns value is "3";
      fm property column widths value is "5cm 5cm 6cm";
    It works. I earn 10 points for answering my own question. :-)
    Ciao
    Jang

  • Setting column widths using CSS...

    Hi guys,
    I am using a simple 2 column table to layout pictures and
    text. The problem I'm having is that I'm not sure how to set the
    column widths and as such when you flick from page to page the
    column widths and don't stay exactly equal to each other as I'd
    like them too.
    This can clearly be seen through clicking and comparing the
    following two pages.
    http://www.fyrne.com/mb_food_and_drink.html
    http://www.fyrne.com/mb_television.html
    Any advice on how I can resolve this would be much
    appreciated.
    Cheers, J

    Hi James,
    I see the scrollbars now but now I also see what you mean :(
    I think the easy fix is to create a class and apply it to
    every single
    td that has the text/image/heading to give them a fixed
    width! (Maybe
    only applying it to the top td's would do the trick... I'm
    really no
    good with tables)
    Hope it made some sense
    JamesFryer skrev:
    > Hi Kim,
    >
    > Thanks for posting this link. I think it was Nadia who
    previously suggested I
    > implement the suggest edcode line to auto add the
    vertical scroll bar and avoid
    > an overall site shift problem I was having.
    >
    > However I have now implemented this and am still getting
    the shift problem -
    > you will notice it is not the overall site (ie the
    bordered area) which is
    > shifting but the internal table columns. I believe I
    have set these column
    > widths in DW design view but this often proves
    problematic (pushing out the
    > width of the main table for no reason although this does
    not actually show when
    > previewed).
    >
    > As such I hoped I would be able to control this through
    CSS - I don't believe
    > it's the same as the shifting problem...
    >
    > Thanks again, J
    >
    Kim
    http://www.geekministry.com

  • Question about setting column width in SQL*Plus using info retrieved w SQL

    Good morning,
    Is there a way to tell SQL*Plus to set the width of a column to the greatest width of the elements found in the column ? (as opposed to the default which is the width declared in the DDL)
    In other words, I'd like to do something functionally equivalent to this:
    COL <columname> format a[select max(length(<columnname>)) from <thetablethatcontainscolumname>]
    I'm doing the above manually in two steps
    1. select max(length(columnname)) from .....
    2. col columnname format a[resultofstep1]
    Is there a way of doing it in one step ?
    Thank you for your help,
    John.

    Hi Munky,
    >
    you should consider whther you are using the correct tool for the job, SQLplus isn't exactly ideal for doing presentation layer stuff
    >
    I'm not really doing presentation stuff, I asked because it would be very convenient for everyday stuff. I commonly query the tables that I am going to deal withm just to have a look at the column names and a few values, something like:
    select * from EMP where rownum <= 10; -- just to have a look at the table and some values
    when the table contains a wide column then the display gets all messed up. It would be nice to have an option or a mechanism to tell SQL*Plus to automatically use the width of the widest value, instead of having to determine the value and then manually set the column.
    thank you for your help, it's good to know that I didn't miss some trivial setting in the documentation that would do it ;)
    John.

  • Setting column width in OBIEE Answers report

    Hi All,
    Not sure if this has been asked before in the forums, but I did not succeeded in finding any clues. We have an OBIEE 10g Answers table view report that we need to display on our dashboard. The problem is that we need to set some width for all the columns in the report so that report does not extends horizontally as data in column grows but not much luck setting width in Column Properties. Since I am a newbie in the world of OBIEE, so I would appreciate any guidance with setting widths in an Answers report.
    Looking forward to your responses.
    Regards,
    Maria

    Hi,
    The best option to do this is :
    1. Create a report which has less data. And in the column properties hide it.
    2. Edit the Dashboard page and there is an option called 'Add Column'
    3. Place the report with the hidden column.
    4. Please hide the complete section and remove the collapsible. And save it
    5. When you view the report, it would not appear in the page but you can view the desired report.
    Please let me know if you still face issues.
    Regards
    MuRam

  • How to set column width in GridPane in FXML?

    I would like to set width, for ex, of column 4 in GridPane.
    I can do like this:
    <columnConstraints>
                <ColumnConstraints prefWidth="100"/>
                <ColumnConstraints prefWidth="200" />
                <ColumnConstraints prefWidth="200" />
                <ColumnConstraints prefWidth="200" />
    </columnConstraints>If i have 10 columns should i add 10 column constraints? (i need to set only width of 4th column)
    How can i do it easier?

    >
    Hi, Can someone please help on how to set the columnwidth in csv file using javacode.
    I used FileWriter class to upload data into the csv file but csv file is taking default width while showing content. Is there a way to set the fixed column width or set width dinamically based on value?
    >
    The fields in CSV (Comma-Separated-Value) files are separated by commas; they do not have a fixed width.

  • AUTO_RESIZE jtable set column width by column header

    Do I need to use one of the AUTO_RESIZE methods, the TableColumnModel, or another method in order to set the default width for a column based on the width of the column header.

    This is a simple question with an answer. In a JTable, how do you set the width of a column depending on the width of the column header?

  • Jatble: setting column-width,why can't I do it here?

    public class SpieleTableModel extends DefaultTableModel {
         * Creates a new instance of SpieleTableModel
        public SpieleTableModel() {
            super();
            //SpieleTable
            addColumn(" Nr.");
            addColumn(" Name");
            addColumn(" max");
            addColumn(" is");
            addColumn(" startet");
            addColumn(" stoppedt");
           // now I want to set the col preferred width
          // this does not work
          TableColum column = getColumnModel().getColumn(0);
        }Is it not possible to set the width right in my class?
    TIA Hanns

    getColumnModel() is not a method of DefaultTableModel:
    http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/table/DefaultTableModel.html

Maybe you are looking for

  • My ipod touch is not showing up in my itunes...can anyone help me?

    I have tried everything!!!

  • IWeb podcasts not working in iWeb 08

    I have been using iWeb 06 to put up podcasts for my church and now that I have a new iMac I was really excited to put the podcasts up using the new features in iWeb 08. However when I put the podcast in iWeb 08, it looks fine and even plays fine, I p

  • Internal Order to track revenues

    Hi All, Wanted to know what setting we make in Internal Order Type so that it can be used for tracking revenues instead of costs. If we don't set this in Internal Orrder Type , then how can we acheive this? When I look at 'Control Tab' at Internal Or

  • Context configuration exception

    Hi, We have a RFC enabled function moudule which returns 2 tables as TABLES parameters. when i use the table1 parameter for a drop down field, it works perfectly. The values are fetched by the RFC and populated in the drop down. But when i use the ta

  • TS3274 I am unable to turn up the volume on my iPad

    I can get my alerts to sound under settings and I can turn the mute button on because the mute icon pops up when I hit the mute button.  But, when I try to adjust the volume the volume gauge does not show up.  How can I fix my my volume button?