Column Width Changed When Importing WorkBook From xlsx?

6 posts, 0 answers
  1. wen
    wen avatar
    6 posts
    Member since:
    May 2011

    Posted 13 Jul Link to this post

    I have A  xlsx file as  Data Template。

    for     

  2. wen
    wen avatar
    6 posts
    Member since:
    May 2011

    Posted 13 Jul Link to this post

    when  i import from  file。

    Workbook wb;

                using (FileStream SourceStream = File.Open(xlsxfilepath, FileMode.Open))
                {

                    XlsxFormatProvider formatProvider = new XlsxFormatProvider();

                    wb = formatProvider.Import(SourceStream);
                }

    column  width  changed。

     

    I  Found  When My Template File, In which  Used  "Normal" CellStyle , has Font isn't  "Calibri",11, Example "宋体",12。

    when I  Import file,

    WorkBook will Restore  "Normal" CellStyle to "Calibri" And Sametime Column Width changed。

     

    Workbook  wb = ExcelWorkBookEngine.OpenWorkbook(@"C:\Users\Administrator\Desktop\test002.xlsx");
    ExcelWorkBookEngine.SaveWorkbook(wb, @"C:\Users\Administrator\Desktop\test002_2.xlsx", out errmsg);

     

    I  Import  File  test002.xlsx And Save To File test002_2.xlsx

    Column Width In  File test002_2.xlsx is diff to Original File!

    When  I  Midify  "Calibri",11 As Normal Style, The Column Width will  Keep !

  3. wen
    wen avatar
    6 posts
    Member since:
    May 2011

    Posted 14 Jul Link to this post

    Files  In My Question List in Attach。

    Can I Keep Column Width ?

     

  4. Peshito
    Admin
    Peshito avatar
    550 posts

    Posted 18 Jul Link to this post

    Hi Wen,

    Thank you for attaching the images. I created a spreadsheet with different column widths and changed the style to Times New Roman. After importing and exporting the file ti loaded as expected. Could you try whether this issue still appears with our latest Release version - R2 2018 SP1? If the issue still persists, please upload the sample document reproducing the problem. As this is a forum thread, you could either open a support thread or upload the document to an online files storage shared space.

    Regards,
    Peshito
    Progress Telerik

  5. wen
    wen avatar
    6 posts
    Member since:
    May 2011

    Posted 21 Jul Link to this post

    If I want change the worksheet cloumn width,by the following:

    worksheet.Columns[i].SetWidth(new ColumnWidth(width, true))

    Problem is, width must is  pixel unit。If  Set width use Excel width unit, char count。

    What  is the  Code?  

  6. Peshito
    Admin
    Peshito avatar
    550 posts

    Posted 25 Jul Link to this post

    Hello,

    The column width is between 0 and 255, which value represents the number of characters that can be displayed in a cell that is formatted with the standard font. You can find more information in "Change the column width and row height" article. To specify the appropriate unit, use Unit's class PointToDip method.

    For example a column width set to 300 pixels is equal to 42.14 of the specified above units of measurement in Excel. 

    Regards,
    Peshito
    Progress Telerik

Back to Top