本文整理汇总了C#中Microsoft.Office.Interop.Excel.Workbook.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Workbook.Save方法的具体用法?C# Workbook.Save怎么用?C# Workbook.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Excel.Workbook
的用法示例。
在下文中一共展示了Workbook.Save方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EditWorkFlow
private Worksheet objExcelWorkSheet; //定义Workbook工作表对象
#endregion Fields
#region Methods
// Change the Mapping WorkFlow @2015-7-16 By CC
public void EditWorkFlow(string StrTestData)
{
objExcelApp = new Microsoft.Office.Interop.Excel.Application();
objExcelWorkBooks = objExcelApp.Workbooks;
objExcelWorkbook = objExcelWorkBooks.Open(StrTestData, 0, false, 5, "", "", true,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
objExcelWorkSheet = (Worksheet)objExcelWorkbook.Worksheets["WorkFlow"]; //strSheetName is the Sheet Name of Exce,if there is no name then Defult is "1"
objExcelWorkSheet.Select(Type.Missing);
int rowsint = objExcelWorkSheet.UsedRange.Cells.Rows.Count; //get the Row Number
int columnsint = objExcelWorkSheet.UsedRange.Cells.Columns.Count;//get the column number
int rowNo = 0;
int ParameterRowNo = 0;
int columnNo = 0;
int FlagColumnNo = 0;
for (int j = 1; j <= columnsint; j++)
{
string strColumnsName = ((Range)objExcelWorkSheet.Cells[1, j]).Text.ToString();
if (strColumnsName == "Flag")
{
FlagColumnNo = j;
}
if (strColumnsName == "BusinessFlow")
{
rowNo = j;
}
if (strColumnsName == "ParameterValue")
{
ParameterRowNo = j;
}
}
for (int i = 2; i <= rowsint; i++)
{
string strFlagValue = ((Range)objExcelWorkSheet.Cells[i, FlagColumnNo]).Text.ToString();
if (strFlagValue =="Y")
{
int RowNO = i;
objExcelWorkSheet.Cells[RowNO, FlagColumnNo] = "N";
}
string strBusinessFlow = ((Range)objExcelWorkSheet.Cells[i, rowNo]).Text.ToString();
if (strBusinessFlow == "HeaderMapping" || strBusinessFlow == "TaxMapping" || strBusinessFlow == "LineItemsMapping")
{
columnNo = i;
string strParameterValue = ((Range)objExcelWorkSheet.Cells[i, ParameterRowNo]).Text.ToString();
if (strParameterValue == "IR" || strParameterValue == "TradeBilling" || strParameterValue == "TradeCredit" || strParameterValue == "TradeDebit" || strParameterValue == "TradeReturn")
{
objExcelWorkSheet.Cells[i, 1] = "Y";
}
}
}
objExcelWorkbook.Save();
objExcelWorkbook.Close(false, StrTestData, false);
objExcelApp.Quit();
NAR(objExcelApp);
NAR(objExcelWorkbook);
NAR(objExcelWorkSheet);
}
示例2: processFolders
//.........这里部分代码省略.........
}
else
{
Folder fol = new Folder();
fol.folder = str4;
fileconturi = recuri;
if (MySheet.Cells[i, 5].Value2 != null)
{
List<Subfolder> lstsf = new List<Subfolder>();
str5 = MySheet.Cells[i, 5].Value.ToString();
//r.Subfolder = str5;
if (MySheet.Cells[i, 13].value2 != null && MySheet.Cells[i, 13].value.ToString() == "g")
{
List<string> lstLvl5 = str5.Split('/').ToList();
foreach (var lll in lstLvl5.Where(x => x.Length > 2))
{
Subfolder sf = new Subfolder();
sf.subfolder = lll.Trim();
lstsf.Add(sf);
//recsuburi = CreateNewRMSubFolder(recuri, lll.Trim(), db, i);
}
}
else
{
Subfolder sf = new Subfolder();
sf.subfolder = str5;
if (MySheet.Cells[i, 7].value2 != null)
{
sf.MigrateLoc = MySheet.Cells[i, 7].Value.ToString();
}
lstsf.Add(sf);
//fol.SubFolders=lstsf;
//
//recsuburi = CreateNewRMSubFolder(recuri, str5, db, i);
}
fol.SubFolders = lstsf;
}
else
{
if (MySheet.Cells[i, 7].value2 != null)
{
fol.MigrateLoc = MySheet.Cells[i, 7].Value.ToString();
}
}
lstFolder.Add(fol);
}
r.Folders = lstFolder;
}
y = 1;
if (str4 != null)
{
MySheet.Cells[i, 8] = fileconturi.ToString();
}
else
{
//Remove for basic testing
//long Newuri = CreateNewRMfolder(str1, str2, str3, str4, str5, str3Title);
//
//Console.WriteLine("New folder created (Uri: " + fileconturi.ToString() + ")");
}
r.SheetLine = i;
//7
//r.RMuri = fileconturi.ToString();
//r.Timestamp = DateTime.Now;
rows.Add(r);
}
sheet.Rows = rows;
sheets.Add(sheet);
//
string json = JsonConvert.SerializeObject(sheets.ToArray());
//FileLocation
var loc = Path.GetDirectoryName(FileLocation);
System.IO.File.WriteAllText(@loc+"\\SSprocessTIP.json", json);
//
MyBook.Save();
MyBook.Close(null, null, null);
MyApp.Quit();
//}
}
catch (Exception exc)
{
MyBook.Save();
MyBook.Close(null, null, null);
MyApp.Quit();
//
Console.WriteLine("Error: "+exc.Message.ToString());
return;
}
}
示例3: ProcessClassFolders
//.........这里部分代码省略.........
Subfolder sf = new Subfolder();
sf.subfolder = str5;
sf.SheetLine = i;
if (MySheet.Cells[i, 7].value2 != null)
{
sf.MigrateLoc = MySheet.Cells[i, 7].Value.ToString();
}
lstsf.Add(sf);
}
fol.SubFolders = lstsf;
}
else
{
if (MySheet.Cells[i, 7].value2 != null)
{
fol.MigrateLoc = MySheet.Cells[i, 7].Value.ToString();
}
}
rows.LastOrDefault().Folders.Add(fol);
}
}
else
{
if (MySheet.Cells[i, 5].Value2 != null)
{
if (rows.LastOrDefault().Folders.LastOrDefault().SubFolders==null)
{
List<Subfolder> lstsf = new List<Subfolder>();
rows.LastOrDefault().Folders.LastOrDefault().SubFolders = lstsf;
}
str5 = MySheet.Cells[i, 5].Value.ToString();
if (MySheet.Cells[i, 13].value2 != null && MySheet.Cells[i, 13].value.ToString() == "g")
{
List<string> lstLvl5 = str5.Split('/').ToList();
foreach (var lll in lstLvl5.Where(x => x.Length > 2))
{
Subfolder sf = new Subfolder();
sf.subfolder = lll.Trim();
sf.SheetLine = i;
if (MySheet.Cells[i, 7].value2 != null)
{
sf.MigrateLoc = MySheet.Cells[i, 7].Value.ToString();
}
rows.LastOrDefault().Folders.LastOrDefault().SubFolders.Add(sf);
}
}
else
{
Subfolder sf = new Subfolder();
sf.subfolder = str5.Trim();
sf.SheetLine = i;
if (MySheet.Cells[i, 7].value2 != null)
{
sf.MigrateLoc = MySheet.Cells[i, 7].Value.ToString();
}
//lstsubfolder.Add(sf);
//fol.SubFolders = lstsubfolder;
//rows.LastOrDefault().Folders.LastOrDefault().SubFolders = lstsubfolder;
rows.LastOrDefault().Folders.LastOrDefault().SubFolders.Add(sf);
}
}
}
//End New
}
sheet.Rows = rows;
sheets.Add(sheet);
//
string json = JsonConvert.SerializeObject(sheets.ToArray());
//FileLocation
var loc = Path.GetDirectoryName(FileLocation);
System.IO.File.WriteAllText(@loc + "\\SSprocessTIP.json", json);
//
MyBook.Save();
MyBook.Close(null, null, null);
MyApp.Quit();
Console.WriteLine("Successful in building Json file.");
Repeatmenu();
//}
}
catch (Exception exc)
{
MyBook.Save();
MyBook.Close(null, null, null);
MyApp.Quit();
//
Console.WriteLine("Error: " + exc.Message.ToString()+" - "+iRow);
return;
}
}
示例4: SynctoExcel
private static void SynctoExcel(string excel, string json)
{
List<Sheets> myMessage = JsonConvert.DeserializeObject<List<Sheets>>(File.ReadAllText(@FileLocation));
MyApp = new Excel.Application();
MyApp.Visible = false;
MyBook = MyApp.Workbooks.Open(@FileLocation);
MySheet = (Excel.Worksheet)MyBook.Sheets["Folder Structure"];
//
foreach (var file in myMessage)
{
foreach (Rows r in file.Rows)
{
var snumber = r.SheetLine;
MySheet.Cells[snumber, 8] = r.RMuri;
MySheet.Cells[snumber, 9] = r.OriginalFileCount;
MySheet.Cells[snumber, 10] = r.RMFileCount;
}
}
MyBook.Save();
MyBook.Close(null, null, null);
MyApp.Quit();
}
示例5: ZvedVidomist
public void ZvedVidomist(int semestr, string subject, string mount)
{
_subject = subject;
Semestr = semestr;
_arabSemestr = semestr == 1 ? ArgDataSet.Tables[CurrentGroupName].Rows[0]["Перше півріччя"].ToString() : ArgDataSet.Tables[CurrentGroupName].Rows[0]["Друге півріччя"].ToString();
string sT;
if (mount.Equals(""))
{
sT = semestr == 1 ? "1-ше півріччя" : "2-ге півріччя";
}
else sT = mount + " місяць";
var existsPath = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.Length - 9)
+ @"Data\" + "Empty book.xls";
var pathTogroup = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.Length - 9)
+ @"User Data\Зведена відомість успішності\" + "Зведена відомість успішності за " + sT + ".xls";
var pathToTamplateVidomist = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.Length - 9)
+ @"Data\" + "Зведена відомість.xls";
if (!System.IO.File.Exists(pathTogroup))
System.IO.File.Copy(existsPath, pathTogroup, true);
_xlApp = new Excel.Application();
_xlApp.DisplayAlerts = false;
_xlWorkBook = _xlApp.Workbooks.Open(pathTogroup);
_xlWorkSheet = (Excel.Worksheet)_xlWorkBook.Worksheets.Item[1];
bool ifExist = true;
for (int i = 1; i <= _xlWorkBook.Sheets.Count; i++)
{
_xlWorkSheet = (Excel.Worksheet)_xlWorkBook.Worksheets.Item[i];
if (_xlWorkSheet.Name.Contains("Sheet") || _xlWorkSheet.Name.Contains("Аркуш") || _xlWorkSheet.Name.Contains("Лист"))
{
_xlWorkSheet.Name = CurrentGroupName;
ifExist = false;
_xlWorkBook.Save();
break;
}
if (!_xlWorkSheet.Name.Equals(CurrentGroupName)) continue;
if (MessageBox.Show(Resources.ExcelWork_ZvedVidomist_Для_поточної_групи__ + CurrentGroupName + Resources.ExcelWork_ZvedVidomist_, "Обережно, ви можете втратити дані", MessageBoxButtons.YesNo) == DialogResult.No)
{
_xlWorkBook.Close();
_xlApp.Quit();
return;
}
//xlWorkSheet.Delete();
ifExist = false;
//xlWorkBook.Save();
break;
}
if (ifExist)
{
_xlWorkBook.Worksheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
_xlApp.DisplayAlerts = false;
_xlWorkBook.Worksheets.get_Item(1).Name = CurrentGroupName;
_xlWorkBook.Save();
}
_xlWorkSheet = _xlWorkBook.Worksheets.get_Item(CurrentGroupName);
ReloadSheet(pathToTamplateVidomist);
String[] forma = { "Іспит", "Д/З", "КП", "Залік", "КП" };
char startX = 'E';
char pos = ++startX;
startX--;
int count = 0;
int otherCount = 0;
for (int i = 0; i < forma.Length; i++)
{
bool bl = false;
for (int row = 0; row < DsRobPlan.Tables[CurrentGroupName].Rows.Count; row++)
{
try
{
if (!DsRobPlan.Tables[CurrentGroupName].Rows[row][forma[i] + " [семестр " + _arabSemestr + "]"].ToString().Equals("0") && i != 2 && i != 4)
{
bl = true;
startX++;
_xlWorkSheet.Cells[9, startX.ToString()].Value = DsRobPlan.Tables[CurrentGroupName].Rows[row]["Назви навчальних дисциплін"].ToString();
_xlWorkSheet.Cells[43, startX.ToString()].Value = DsRobPlan.Tables[CurrentGroupName].Rows[row]["викладач"].ToString();
_xlWorkSheet.Cells[43, startX.ToString()].Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
_xlWorkSheet.Cells[9, startX.ToString()].Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
_xlWorkSheet.Cells[9, startX.ToString()].ColumnWidth = ColumnWidth(DsRobPlan.Tables[CurrentGroupName].Rows[row]["Назви навчальних дисциплін"].ToString());
count++;
}
}
catch (ArgumentException)
{
continue;
}
if (row == DsRobPlan.Tables[CurrentGroupName].Rows.Count - 1 && i != 2 && i != 4 && bl)
{
_xlWorkSheet.Range[pos.ToString() + 8, startX.ToString() + 8].Merge();
//.........这里部分代码省略.........
示例6: InsertRowsValues
// Insert Row in the Driver.xls
public void InsertRowsValues(string StrDriverPath, string StrCaseName, string StrTestDataPath, string StrComCode, string StrAsset, string StrRunTime)
{
objExcelApp = new Microsoft.Office.Interop.Excel.Application();
objExcelWorkBooks = objExcelApp.Workbooks;
objExcelWorkbook = objExcelWorkBooks.Open(StrDriverPath, 0, false, 5, "", "", true,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
objExcelWorkSheet = (Worksheet)objExcelWorkbook.Worksheets["Driver"]; //strSheetName是指的Exce工作簿的Sheet名,如果没有命名则为"1"
objExcelWorkSheet.Select(Type.Missing);
int rowsint = objExcelWorkSheet.UsedRange.Cells.Rows.Count; //得到行数
if (rowsint > 1)
{
for (int i = 2;i <= rowsint; i++)
{
string strFlagValue = ((Range)objExcelWorkSheet.Cells[i, 1]).Text.ToString();
if (strFlagValue == "Y")
{
int RowNO = i;
objExcelWorkSheet.Cells[RowNO, 1] = "N";
}
}
}
if (rowsint == 1)
{
rowsint = 2;
}
objExcelWorkSheet.Cells[rowsint, 1] = "Y";
objExcelWorkSheet.Cells[rowsint, 2] = "fa_30_saptao_mec";
objExcelWorkSheet.Cells[rowsint, 3] = StrRunTime;
objExcelWorkSheet.Cells[rowsint, 4] = StrRunTime;
objExcelWorkSheet.Cells[rowsint, 5] = StrCaseName;
objExcelWorkSheet.Cells[rowsint, 6] = StrTestDataPath;
objExcelWorkSheet.Cells[rowsint, 7] = "Run";
objExcelWorkSheet.Cells[rowsint, 8] = StrComCode;
objExcelWorkSheet.Cells[rowsint, 9] = StrAsset;
objExcelWorkbook.Save();
objExcelWorkbook.Close(false, StrDriverPath, false);
objExcelApp.Quit();
NAR(objExcelApp);
NAR(objExcelWorkbook);
NAR(objExcelWorkSheet);
}
示例7: dokument_beschreiben
private void dokument_beschreiben(String[] zuordnungen)
{
document_path = tbx_path.Text;
try
{
wu_liste = myExcel.Workbooks.Open(@document_path);
myExcel.Visible = false;
slist = (Worksheet)wu_liste.Sheets[1];
klist = (Worksheet)wu_liste.Sheets[2];
slist_range = slist.UsedRange;
klist_range = klist.UsedRange;
add_item_to_log("Zuordnungen werden in Tabelle eingetragen");
for (int i = 0; i < zuordnungen.Length; i++)
{
string erstwahl = Convert.ToString(slist_range.Cells[i + 2, SPALTE_ERSTWAHL].Value);
if (erstwahl != null)
{
if (erstwahl.Trim() == "") erstwahl = null;
}
if (zuordnungen[i] != null)
{
slist_range.Cells[i + 2, SPALTE_ZUORDNUNG].Value = zuordnungen[i];
slist_range.Cells[i + 2, SPALTE_ZUORDNUNG + 1].Value = null;
slist_range.Cells[i + 2, SPALTE_WUSTUNDENNEU].Value = schueler_wustunden[i] + kurse_stunden[kurse_id.IndexOf(zuordnungen[i])];
}
else if ((schueler_wustunden[i] < 5) || (erstwahl != null))
{
slist_range.Cells[i + 2, SPALTE_ZUORDNUNG].Value = null;
slist_range.Cells[i + 2, SPALTE_ZUORDNUNG + 1].Value = "!";
}
else
{
slist_range.Cells[i + 2, SPALTE_ZUORDNUNG].Value = null;
}
}
wu_liste.Save();
wu_liste.Close();
}
catch (System.Runtime.InteropServices.COMException)
{
MessageBox.Show("Datei existiert nicht\noder andere COMException");
}
finally
{
try
{
wu_liste.Save();
wu_liste.Close();
}
catch (Exception)
{
}
}
}
示例8: dokument_auslesen
private void dokument_auslesen()
{
document_path = tbx_path.Text;
int schueler_anzahl = new int();
try
{
// Pfad wird ausgelesen
wu_liste = myExcel.Workbooks.Open(@document_path);
// Variablen init
myExcel.Visible = false;
slist = (Worksheet)wu_liste.Sheets[1];
klist = (Worksheet)wu_liste.Sheets[2];
slist_range = slist.UsedRange;
klist_range = klist.UsedRange;
schueler_id.Clear();
schueler_namen.Clear();
schueler_vornamen.Clear();
schueler_klasse.Clear();
schueler_klassenlehrer.Clear();
schueler_erstwahl.Clear();
schueler_zweitwahl.Clear();
schueler_drittwahl.Clear();
kurse_id.Clear();
kurse_maxpersonen.Clear();
kurse_minpersonen.Clear();
add_item_to_log("Schüler werden ausgelesen");
for (int i = 0; !String.Equals(slist_range.Cells[i + 2, SPALTE_NAME].Value, null); i++)
{
if (i % 25 == 24)
{
add_item_to_log(Convert.ToString(i + 1) + " Schüler wurden ausgelesen");
}
schueler_id.Add(i + 2);
String name = slist_range.Cells[i + 2, SPALTE_NAME].Value;
String vorname = slist_range.Cells[i + 2, SPALTE_VORNAME].Value;
String klasse = slist_range.Cells[i + 2, SPALTE_KLASSE].Value;
String klassenlehrer = slist_range.Cells[i + 2, SPALTE_KLASSENLEHRER].Value;
String erstwahl = slist_range.Cells[i + 2, SPALTE_ERSTWAHL].Value;
String zweitwahl = slist_range.Cells[i + 2, SPALTE_ZWEITWAHL].Value;
String drittwahl = slist_range.Cells[i + 2, SPALTE_DRITTWAHL].Value;
String zuordnung = slist_range.Cells[i + 2, SPALTE_ZUORDNUNG].Value;
String wustunde = Convert.ToString(slist_range.Cells[i + 2, SPALTE_WUSTUNDENALT].Value);
if (!String.IsNullOrWhiteSpace(name)) schueler_namen.Add(name.Trim());
else schueler_namen.Add(null);
if (!String.IsNullOrWhiteSpace(vorname)) schueler_vornamen.Add(vorname.Trim());
else schueler_vornamen.Add(null);
if (!String.IsNullOrWhiteSpace(klasse)) schueler_klasse.Add(klasse.Trim());
else schueler_klasse.Add(null);
if (!String.IsNullOrWhiteSpace(klassenlehrer)) schueler_klassenlehrer.Add(klassenlehrer.Trim());
else schueler_klassenlehrer.Add(null);
if (!String.IsNullOrWhiteSpace(erstwahl)) schueler_erstwahl.Add(erstwahl.Trim());
else schueler_erstwahl.Add(null);
if (!String.IsNullOrWhiteSpace(zweitwahl)) schueler_zweitwahl.Add(zweitwahl.Trim());
else schueler_zweitwahl.Add(null);
if (!String.IsNullOrWhiteSpace(drittwahl)) schueler_drittwahl.Add(drittwahl.Trim());
else schueler_drittwahl.Add(null);
if (!String.IsNullOrWhiteSpace(zuordnung)) schueler_zuordnung.Add(zuordnung.Trim());
else schueler_zuordnung.Add(null);
if (!String.IsNullOrWhiteSpace(wustunde)) schueler_wustunden.Add(Convert.ToInt32(wustunde.Trim()));
else schueler_wustunden.Add(0);
schueler_anzahl = i;
}
add_item_to_log("Alle " + Convert.ToString(schueler_anzahl + 1) + " Schüler wurden ausgelesen");
add_item_to_log("Kurse werden ausgelesen");
for (int i = 0; !String.Equals(klist_range.Cells[i + 2, SPALTE_KURSID].Value, null); i++)
{
kurse_id.Add(klist_range.Cells[i + 2, SPALTE_KURSID].value);
kurse_name.Add(klist_range.Cells[i + 2, SPALTE_KURSNAMEN].value);
kurse_maxpersonen.Add(Convert.ToInt32(klist_range.Cells[i + 2, SPALTE_MAXPERSONEN].value));
kurse_minpersonen.Add(Convert.ToInt32(klist_range.Cells[i + 2, SPALTE_MINPERSONEN].value));
kurse_stunden.Add(Convert.ToInt32(klist_range.Cells[i + 2, SPALTE_KSTUNDEN].value));
kurse_size.Add(0);
}
add_item_to_log("Auslesen vollendet");
wu_liste.Save();
wu_liste.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
try
{
wu_liste.Save();
wu_liste.Close();
}
catch (Exception)
{
}
}
}