我正在尝试使用 C#.net 创建一个 excel 文档。但是在我可以正确地将一些值写入单元格之后,最后一个单元格有奇怪的字符,例如与我从一个简单的 txt 文件中读取的内容无关:
����Q%RSIG5oH�g7�j�FnJ�9������RG8��P;����K}r����i��������:�+��J �F��]dF��Y���Pd���1�C�OӘ$D0�..r
这是我的 excel 创建者类:
class CreateExcelDoc
{
Microsoft.Office.Interop.Excel.Application ExcelUygulama;
Microsoft.Office.Interop.Excel.Workbook ExcelProje;
Microsoft.Office.Interop.Excel.Worksheet ExcelSayfa;
object Missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Range ExcelRange;
string s_dosyaadi = "";
string s_veri = "";
public CreateExcelDoc()
{
ExcelUygulama = new Microsoft.Office.Interop.Excel.Application();
ExcelProje = ExcelUygulama.Workbooks.Add(Missing);
ExcelSayfa = (Microsoft.Office.Interop.Excel.Worksheet)ExcelProje.Worksheets.get_Item(1);
ExcelRange = ExcelSayfa.UsedRange;
ExcelSayfa = (Microsoft.Office.Interop.Excel.Worksheet)ExcelUygulama.ActiveSheet;
ExcelUygulama.Visible = false;
ExcelUygulama.AlertBeforeOverwriting = false;
}
public void HucreyeYaz(int row, int col, string s_veri) // write to a cell
{
if (s_veri != "" && row != 0 && col != 0)
{
Microsoft.Office.Interop.Excel.Range bolge = (Microsoft.Office.Interop.Excel.Range)ExcelSayfa.Cells[row, col];
bolge.Value2 = s_veri;
}
}
public void Kaydet() // saves the excel document
{
ExcelProje.SaveAs(@"C:\excels\dosya.xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Missing, Missing, false, Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange);
ExcelProje.Close(true, Missing, Missing);
ExcelUygulama.Quit();
}
}