/// <summary> /// List<string>转xml /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { try { List<string> std = new List<string>(); for (int irow = 0; irow < standardcells.Count(); irow++) { List<ICell> row = standardcells[irow]; for (int icol = 0; icol < row.Count(); icol++) { std.Add(row[icol].StringCellValue); } } using (System.IO.StringWriter stringWriter = new StringWriter(new StringBuilder())) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<string>)); xmlSerializer.Serialize(stringWriter, std); FileStream fs = new FileStream("list_userModel.xml", FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(fs); sw.Write(stringWriter.ToString()); sw.Close(); fs.Close(); MessageBox.Show("写入文件成功!"); } } catch (System.Exception ex) { System.Console.WriteLine("===================================="); System.Console.WriteLine(ex.Message); System.Console.WriteLine(ex.StackTrace); } }