簡體   English   中英

C#-Interop Excel適合尺寸單元格

[英]C# - Interop Excel fit size cells

我正在使用C#開發Windows窗體應用程序,並且已經在其上實現了Interop for Excel以創建包含一些數據的工作表。

我已經可以創建excel文檔,但是當我打開它時,單元格的大小如下所示:

在此處輸入圖片說明

我已經在代碼上實現了一些功能來嘗試解決此問題:

char[] NosCharsToRemove = "\n".ToCharArray();
ExcelWorkSheet.Cells[row, col] = norm.comments.TrimStart(NosCharsToRemove);

要么,

ExcelWorkSheet.Cells[row, col] = norm.comments.TrimStart();

要么,

ExcelWorkSheet.Cells[row, col] = norm.comments.Replace(System.Environment.NewLine, "");

但是沒有人工作。

如果轉到Excel文檔,然后在“丑陋”單元格之一中雙擊,然后將焦點放在另一個隨機單元格上,則“丑陋單元格”將固定為“魔術”。

在此處輸入圖片說明

有誰知道我該如何以編程方式解決此問題?

我將非常感謝他們的幫助!

嘗試為該單元使用自動換行樣式。 有關范圍請參考msdn wordwrap

ExcelWorkSheet.Cells[row, col].Style.Alignment.WrapText = true;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM