This is a migrated thread and some comments may be shown as answers.

Column Width Changed When Importing WorkBook From xlsx?

5 Answers 40 Views
SpreadProcessing
This is a migrated thread and some comments may be shown as answers.
wen
Top achievements
Rank 1
wen asked on 14 Jul 2018, 04:32 AM

I have A  xlsx file as  Data Template。

for     

5 Answers, 1 is accepted

Sort by
0
wen
Top achievements
Rank 1
answered on 14 Jul 2018, 04:48 AM

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 !

0
wen
Top achievements
Rank 1
answered on 14 Jul 2018, 05:03 AM

Files  In My Question List in Attach。

Can I Keep Column Width ?

 

0
Peshito
Telerik team
answered on 18 Jul 2018, 10:45 AM
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

0
wen
Top achievements
Rank 1
answered on 21 Jul 2018, 04:26 PM

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?  

0
Peshito
Telerik team
answered on 25 Jul 2018, 08:04 AM
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

Tags
SpreadProcessing
Asked by
wen
Top achievements
Rank 1
Answers by
wen
Top achievements
Rank 1
Peshito
Telerik team
Share this question
or